Product Documentation
Product DocumentationDeveloper GuideAPI ReferenceHelp Center
  • About Search.io
  • Fundamentals
    • Search settings
      • Understanding relevance and ranking
      • Textual relevance
      • Ranking adjustments
      • Dynamic boosting
      • Synonyms
      • Redirects
    • Promotion rules
      • Triggers
      • Manual curation
      • Boosting
      • Banners
    • Integrating search
      • Display options
      • Filters and sort options
      • Result templates
      • Search UI integration
    • Roles & permissions
    • Reporting
      • Event tracking
      • Trends
      • Content issues
      • Explore
    • Filter expressions
    • Indexing Data
      • Schema
  • Guides
    • General
      • Previewing results
    • 📄Content websites
      • Crawling a website
      • Adding custom fields
      • Configuring domains
      • Excluding documents
      • Improving content
    • 🛍️E-commerce
      • Define schema and sync data
      • Relevance tuning
      • Creating a user interface
      • Adding a sale banner
  • Integrations
    • Shopify
      • Shopify metafields
    • Webflow
    • Drupal
    • Wordpress
  • Deep dives
    • Concepts and terminology
    • How Search.io works
    • Autocomplete
    • Spelling
  • Helpful Links
    • Developer Documentation
    • API Reference
    • Help Center
Powered by GitBook
On this page
  • Get started
  • Installation

Was this helpful?

  1. Integrations

Wordpress

Add advanced search and discovery capabilities to any Wordpress site in minutes.

PreviousDrupalNextConcepts and terminology

Last updated 3 years ago

Was this helpful?

Get started

Follow the . Once your collection is up and running, you are ready to install Search.io onto your Wordpress website.

Head over to the in your console and customise the search interface to suits your needs.

For this demonstration we are going to be using the results page configuration. If you're looking to use the overlay configuration, we have a guide you can checkout.

Click install and keep the two code snippets handy!

Installation

Header template

The two code snippets we generated before need to be added to our theme's template files.

The first snippet will be added to our global header.php template file. This snippet will show the search input in the header area on every page of our site.

Note that we are using a child theme for the Twenty Twenty Wordpress theme.

At the moment our header looks like this:

We're going to be replacing the default Wordpress search function with Search.io search.

Click to expand example
<?php
  if ( has_nav_menu( 'primary' ) || ! has_nav_menu( 'expanded' ) ) {...
?>
<div data-widget="search-input">
	<script type="application/json">
		{
		"account": "1583472911415671216",
		"collection": "searchio-wordpress",
		"endpoint": "//jsonapi-us-valkyrie.sajari.net",
		"pipeline": "website",
		"preset": "website",
		"variables": {},
		"mode": "suggestions",
		"redirect": {
			"url": "/search"
		},
		"theme": {
			"color": {
			"primary": {
				"base": "#667eea",
				"text": "#ffffff",
				"active": "#5a67d8"
			    }
			}
		}
		}
	</script>
	<noscript>This page requires JavaScript</noscript>
</div>
<script async src="https://cdn.sajari.com/embed/1/loader.js"></script>
</div><!-- .header-navigation-wrapper -->
</div><!-- .header-inner -->
</header><!-- #site-header -->
<?php
// Output the menu modal.
get_template_part( 'template-parts/modal-menu' );

Take note of the redirect url in the above code snippet, as this will be important later.

Now we have the search input up and running in our global header.php template file and on every page on our site:

Search results page template

Our next step is to install the search results on our results page. To do this we will create a new page in our Wordpress dashboard and call it 'search' so it has the slug /search.

We'll then take our second code snippet, and place it in the page-search.php template file where we want the search results to render. In our example we are placing it right after the get_header() function in the main body of our page template.

Click to expand example
<?php
/**
 * The template for the /search page
 */
get_header();
?>
<main id="site-content" role="main">
	<div class="section-inner">
	<h2 style="text-align:center; margin-bottom: 2rem;">
	<?php global $post;
	echo get_the_title($post->ID);
	?>
	</h2>
	<div data-widget="search-results">
		<script type="application/json">
			{
			"account": "1583472911415671216",
				"collection": "searchio-wordpress",
				"endpoint": "//jsonapi-us-valkyrie.sajari.net",
				"pipeline": "website",
				"preset": "website",
				"variables": {},
				"filters": [],
				"options": {
					"sorting": {
					"options": [
						{
						"name": "Most relevant",
						"value": ""
						},
						{
						"name": "Alphabetical: A to Z",
						"value": "title"
						},
						{
						"name": "Alphabetical: Z to A",
						"value": "-title"
						},
						{
						"name": "Date: Oldest to Newest",
						"value": "created_at"
						},
						{
						"name": "Date: Newest to Oldest",
						"value": "-created_at"
						}
					]
					},
					"results": {
					"viewType": "list",
					"showVariantImage": false,
					"imageAspectRatio": {
						"grid": 0.563,
						"list": 1
					},
					"imageObjectFit": {
						"grid": "cover",
						"list": "cover"
					}
					},
					"showViewType": true,
					"input": {
					"hide": true,
					"position": "aside"
					}
				},
				"theme": {
					"color": {
					"primary": {
						"base": "#667eea",
						"text": "#ffffff",
						"active": "#5a67d8"
					}
					}
				},
				"customClassNames": {
					"results": {
					"template": {
						"container": "list"
					}
					}
				}
				}
			</script>
			<noscript>This page requires JavaScript</noscript>
		</div>
	</div>
</main><!-- #site-content -->
<?php get_template_part( 'template-parts/footer-menus-widgets' ); ?>
<?php get_footer(); ?>

Because we set the redirect url to /search in our search-input code snippet any search from the site's header will take us to our new search page:

In header.php place the snippet you copied from before where you would like it. In our example we are removing all mentions of the default Wordpress site search and placing our search-input snippet after the has_nav_menu() function and before the </header>:

We can then create a new template file in our theme directory for our search page and call it page-search.php, following the .

That's it! You now have powerful search up and running on your Wordpress site

🎉
Wordpress template hierarchy
search input
get started guide for websites
search interface builder
here