Skip to content

Search Widget

The Freespoke Search Widget lets you add Freespoke-powered search to any website. It works as a standalone JavaScript embed or as a WordPress plugin.

Quick start

Add the widget script with your client ID:

<!-- Add the widget script with your client ID -->
<script src="https://freespoke.com/widgets/freespoke-search/embed/index.js"
data-client-id="YOUR_CLIENT_ID"
defer>
</script>
<!-- Widget container (created automatically if not present) -->
<div id="freespoke-widget-container"></div>

The widget initializes automatically when the script loads.

Configuration options

Core configuration

AttributeTypeDefaultDescription
data-client-idstringRequiredYour unique client identifier
data-containerstringfreespoke-widget-containerID of the container element where the widget renders
data-placeholderstringSearch ...Placeholder text for the search input
data-themestringlightVisual theme: light, dark, or auto

Search behavior

AttributeTypeDefaultDescription
data-auto-searchbooleanfalseAutomatically search when URL contains a query parameter
data-query-paramstringqURL parameter name for the search query (used with data-auto-search)
data-embedded-searchbooleanfalseShow search results inline instead of redirecting
data-redirect-urlstringURL template for search redirect, with {query} as the placeholder (e.g. /search?q={query}). Only used when data-embedded-search is false
data-redirect-targetstring_selfWhere to open the redirect URL: _self or _blank

Examples

<script src="https://freespoke.com/widgets/freespoke-search/embed/index.js"
data-client-id="YOUR_CLIENT_ID"
data-auto-search="true"
data-query-param="q"
data-embedded-search="true"
defer></script>
<div id="freespoke-widget-container"></div>

When users visit yoursite.com/search?q=climate, the widget automatically searches for “climate”.

Search bar with redirect

<script src="https://freespoke.com/widgets/freespoke-search/embed/index.js"
data-client-id="YOUR_CLIENT_ID"
data-embedded-search="false"
data-redirect-url="/search?q={query}"
data-placeholder="Search our site..."
defer></script>
<div id="freespoke-widget-container"></div>

Styling

Container styling

Style the widget container with CSS to match your site:

#freespoke-widget-container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

Preventing layout shift

Set a minimum height on the container to prevent content layout shift while the widget loads:

#freespoke-widget-container {
min-height: 60px; /* Search bar only: ~60px */
/* OR */
min-height: 400px; /* With search results: ~400px+ */
}

Theme customization

The widget supports extensive theme customization through data-style-* attributes. Customizations take priority over the built-in theme.

Basic theme usage

<!-- Light theme (default) -->
<script
src="https://freespoke.com/widgets/freespoke-search/embed/index.js"
data-client-id="your-client-id"
data-theme="light">
</script>
<!-- Dark theme -->
<script
src="https://freespoke.com/widgets/freespoke-search/embed/index.js"
data-client-id="your-client-id"
data-theme="dark">
</script>

Custom colors

<script
src="https://freespoke.com/widgets/freespoke-search/embed/index.js"
data-client-id="your-client-id"
data-style-primary-bg="#ffffff"
data-style-primary-text="#2d3748"
data-style-primary-border="#e2e8f0"
data-style-button-bg="#4299e1"
data-style-button-text="#ffffff"
data-style-button-hover-bg="#3182ce">
</script>

Mode-specific colors

Set different colors for light and dark modes by adding light- or dark- after data-style-:

<script
src="https://freespoke.com/widgets/freespoke-search/embed/index.js"
data-client-id="your-client-id"
data-style-light-primary-bg="#ffffff"
data-style-light-primary-text="#2d3748"
data-style-light-button-bg="#4299e1"
data-style-dark-primary-bg="#1a202c"
data-style-dark-primary-text="#f7fafc"
data-style-dark-button-bg="#63b3ed">
</script>

Typography and spacing

<script
src="https://freespoke.com/widgets/freespoke-search/embed/index.js"
data-client-id="your-client-id"
data-style-font-family="'Inter', -apple-system, sans-serif"
data-style-font-size="16px"
data-style-font-size-small="14px"
data-style-font-size-large="18px"
data-style-border-radius="8px"
data-style-transition-duration="200ms">
</script>

Available theme properties

Color properties

PropertyDescriptionExample
data-style-primary-bgMain background color#ffffff
data-style-primary-textPrimary text color#3b4355
data-style-primary-borderPrimary border color#e1e5eb
data-style-secondary-bgSecondary background color#f9fafb
data-style-secondary-textSecondary text color#606671
data-style-secondary-borderSecondary border color#e5e7eb

Button colors

PropertyDescriptionExample
data-style-button-bgButton background color#222222
data-style-button-textButton text color#ffffff
data-style-button-hover-bgButton hover background color#1f2937
data-style-button-hover-textButton hover text color#ffffff
data-style-button-borderButton border color#222222

Input colors

PropertyDescriptionExample
data-style-input-bgInput background color#ffffff
data-style-input-textInput text color#3b4355
data-style-input-borderInput border color#e1e5eb
data-style-input-placeholderInput placeholder text color#9ca3af
PropertyDescriptionExample
data-style-link-textLink text color#2563eb
data-style-link-hover-textLink hover text color#1d4ed8

Status colors

PropertyDescriptionExample
data-style-error-bgError background color#fef2f2
data-style-error-textError text color#dc2626
data-style-error-borderError border color#fecaca

Typography

PropertyDescriptionExample
data-style-font-familyFont family'Inter', sans-serif
data-style-font-sizeBase font size16px
data-style-font-size-smallSmall font size14px
data-style-font-size-largeLarge font size18px

Spacing and layout

PropertyDescriptionExample
data-style-border-radiusDefault border radius4px
data-style-border-radius-smallSmall border radius2px
data-style-border-radius-largeLarge border radius8px
data-style-transition-durationAnimation transition duration150ms

Complete branding example

<script
src="https://freespoke.com/widgets/freespoke-search/embed/index.js"
data-client-id="your-client-id"
data-theme="light"
data-embedded-search="true"
data-placeholder="Search our knowledge base..."
data-style-primary-bg="#fafafa"
data-style-primary-text="#1a1a1a"
data-style-primary-border="#e0e0e0"
data-style-secondary-bg="#f5f5f5"
data-style-secondary-text="#666666"
data-style-button-bg="#0066cc"
data-style-button-text="#ffffff"
data-style-button-hover-bg="#0052a3"
data-style-input-bg="#ffffff"
data-style-input-text="#1a1a1a"
data-style-input-placeholder="#999999"
data-style-font-family="'Source Sans Pro', -apple-system, sans-serif"
data-style-font-size="15px"
data-style-font-size-large="17px"
data-style-border-radius="6px"
data-style-transition-duration="200ms">
</script>

Troubleshooting

Widget not appearing

  • Check the browser console for errors
  • Verify the script loads after the DOM element exists, or use the defer attribute
  • Confirm the container element exists in the page
  • Ensure data-client-id is provided

CORS issues

  • Ensure your domain is whitelisted by Freespoke
  • Use HTTPS in production
  • Contact support for domain verification

Auto-search not working

  • Verify data-auto-search="true" is set
  • Check data-query-param matches the URL parameter name
  • Ensure the URL parameter value is properly encoded
  • Confirm data-embedded-search="true" is set to display results

Browser support

The widget supports all modern browsers:

  • Chrome 90+
  • Firefox 88+
  • Safari 14+
  • Edge 90+

Internet Explorer is not supported.

Support

For help with widget integration or to request a client ID, contact us at [email protected].