We use cookies to make your viewing experience better. By accepting you consent, you agree to our Cookie policy

Improve your Craft CMS skills

How To Add A Search Box In Craft CMS

10 min read
Shape April 2022 HR 45

Want to turbo-charge your Craft CMS website with lightning fast search that keeps users glued to your content? A search box gives visitors a shortcut to precisely the information they need. No more fruitless menu hunting or category guessing. Just effortless content discovery tailored to their intent.

This guide packs step-by-step advice on implementing seamless site search with Craft CMS for boosted engagement. You’ll learn expert tips on everything from optimizing relevance to leveraging analytics data to take your on-site search from basic to best-in-class.

To add a search box in Craft CMS, first choose a search plugin - either the native option or a third-party like Solr/Algolia. Install and configure the plugin, mapping content to index. Embed the search form in templates and style it. Optimize relevance through analytics. Implement features like search suggestions and location filtering to improve user experience.

Benefits of Site Search for Craft CMS Websites

Improved Site Navigation and Content Discovery

Adding a site search bar or box is one of the most impactful enhancements you can make for ease of navigation and content findability on a Craft CMS powered website. Rather than having to fumble through menus and categories, users can simply type a keyword or phrase and instantly see relevant pages, posts and documents.

This can drastically improve general website usability, particularly for sites with extensive content catalogs. No longer will users need to guess which subpage or category a piece of information might be hiding under. The search box gives them a direct line to the content they want.

By having an always accessible search option, users are empowered to explore and discover content beyond the main navigation architecture. Search opens up content that might otherwise go undiscovered if buried away in a rarely visited section of the site. It essentially unlocks the full depth of informative content for visitors in a way traditional navigation cannot.

The enhanced content discoverability also applies to returning visitors. They may have previously visited pages that would be difficult to relocate through manual browsing alone. Search provides an instant avenue back to material they want to reference again.

Overall, site search transforms the user experience from one of hunting around a website to simply looking up whatever content they need. It streamlines the content consumption process and reduces friction in the quest for information. For site owners, improving user experience and engagement through search functionality is a no brainer.

Enhanced User Experience

Beyond core search functionality, site search can greatly enhance the overall user experience when implemented thoughtfully. This means going beyond just a basic search box to provide intuitive search interactions.

For example, having autocomplete and search suggestions pop up as users type their query gives them a faster route to the right page or content item. If what they are searching for appears in the suggestion list, they can simply select it rather than completing their full search term.

Additionally, using predictive search technology allows searches to return helpful results even when users misspell or use the wrong terminology. Rather than getting zero results back, predictive capabilities will aim to discern what content they were likely intending to look for.

These small UX tweaks improve the chance of users finding what they want on the first search attempt. Minimal frustration and seamless content lookup equals happy website visitors who will return in the future.

Other search box enhancements like filters, sort options and scoping searches to particular content types or sections can also streamline the user experience. When implemented with care, site search morphs from a functional tool to an intuitive web assistant at your visitors' fingertips.

Increased User Engagement

It has been shown time and again that the easier a website makes it for visitors to find relevant content, the more engaged those users tend to become. Fostering increased engagement is another major benefit of intelligent site search capabilities.

By connecting users directly to topics and information they have a genuine interest in, search can facilitate more meaningful interactions with your site. Visitors spend less time hunting and more time consuming content tailored to their needs.

These personalised journeys keep users active on site pages longer. They are apt to click through to additional content from pages they found via search. With their interest piqued they will explore related topics more eagerly when search served up the first piece of valuable information.

Also, by catering to search intent so effectively site search encourages return visits. If users associate your site with quick access to information they want, they will have a much stronger incentive to come back in future.

Making it a breeze for your audience to uncover your best content pays dividends across many engagement metrics. Search is one of the most powerful tools at your disposal for turning casual visitors into loyal site users who interact with more content during each visit.

Overview of Search Plugins for Craft CMS

Native Craft CMS Search

Out of the box, Craft CMS comes with a built-in native search feature that provides basic but useful site search functionality. It indexes common content like entries, categories, assets, users and commerce products.

The native search builds its index in the background so it's always up to date when users run a query. It also handles typos and common spelling mistakes quite well to return results even if the search term isn't an exact keyword match.

On the downside, the native search isn't as fully featured or fast as some third party solutions. It lacks more advanced capabilities like predictive search suggestions, filters and full control over index settings. It also isn't focused on optimising for relevancy and can return results in an order that isn't ideal.

However, for many websites with a modest amount of content, the native Craft search provides sufficient capabilities out of the box. It's a good option to start off with and later upgrade if more robust functionality is needed. The native search simplifies implementation, avoiding the need to configure plugins or external services initially.

Third-Party Plugins

For large websites or those requiring advanced search capabilities, third-party Craft plugins integrate powerful dedicated search services. Popular options like Solr, Algolia and MeiliSearch connect Craft to enterprise-grade search engines with extensive features.

Solr is an open source search platform with comprehensive capabilities like cached search, relevancy tuning and multi-language support. It offers incredible customisation but requires more technical expertise to implement and manage. Pricing is based on support packages versus usage.

Algolia provides hosted search via their SaaS platform with premium performance and easy integration. It's focused on developer experience and end-user relevancy. Algolia has flexible plans based on monthly search volume starting at their free Hacker plan up to Enterprise offerings.

MeiliSearch combines easy integration like Algolia with open source capabilities similar to Solr. It's designed specifically for fast and relevant search experiences. MeiliSearch has generous free usage tiers and paid plans for high traffic sites that start at $29/month.

In general third-party search plugins deliver greater speed, customisation potential and result relevancy versus Craft's native option. They integrate seamlessly with the Craft API and template code. The choice comes down to site scale, search requirements and technical capabilities when evaluating plugins.

Choosing the Right Search Plugin

Determining the appropriate search plugin for a Craft CMS website depends on assessing both site needs and technical capabilities. Key factors to evaluate include:

  • Site content and traffic - More content and higher traffic requires better performance and capabilities.

  • Search volume expectations - More searches may justify a paid third-party plugin versus native.

  • Feature needs - Do you require advanced functionality like filters, facets or synonyms?

  • Relevancy requirements - How refined do the results need to be for users?

  • Technical abilities - Open source options allow customisation but require more expertise.

  • Budget - Some third-party plugins have monthly fees based on usage.

For most small to mid-sized sites, Craft's native search is a great starting point. It delivers core search functionality without added complexity.

As sites scale, grow and require a more tailored search experience, migrating to a premium plugin like Algolia or MeiliSearch is recommended. Their balance of capabilities, developer experience and costs make search upgrades seamless.

The needs assessment should guide you toward the right plan whether sticking with native or evaluating third-party plugins. Make search decisions based on creating the best user experience within project budget and capabilities.

Displaying and Styling the Search Box

Embedding the Search Form

Once a search plugin is activated in Craft CMS, embedding the search box or form in templates is straightforward. The plugin provides the necessary template code to display the search input field and submit button wherever you want them to appear.

There are several common placement options to consider including: in the primary header or navigation menu bar which gives the search top visibility on all pages; in sidebars or widget areas that allow it to be displayed alongside main content; in the footer which is less prominent but can supplement other search placement; on dedicated solo search pages that showcase all the features; or within specific template files so search only appears on certain sections of the site.

The code can be added directly in Twig templates or output via a search widget if the theme has widget support. This enables drag and drop search placement while editing layouts and themes. For responsive sites, the search box can adapt to mobile views by collapsing into the mobile menu or expanding to a full width box as needed. Experimentation will reveal the optimal search placement for both desktop and mobile screens.

Design and Styling Considerations

Once search functionality is added, attention turns to styling it according to brand design language and UX principles. Some best practices involve using fonts, colors and styles that align with the overall site look to maintain a consistent visual experience. The search box styling should also be appropriate for its location on the page - more muted in sidebars versus prominently styled in main headers. Utilizing white space and spacing around the box makes it clear and scannable, avoiding a cluttered feel.

Hierarchy, contrast and visual styling can selectively draw attention to the search box when desired. At the same time, ornamentation that distracts from usability should be avoided - the focus should remain on an integrated and seamless search experience. Subtle animation and visual feedback after submitting can enhance the overall interaction. Inspiration can be gathered by analyzing search implementations on leading websites and applying relevant learnings about aesthetics and UX to your own search integration and styling.

Responsiveness and Mobile-Friendliness

With most traffic now occurring on mobile, ensuring the search box looks and functions excellently on smartphones is critical. Some tips include using relative sizing so the box resizes across different viewport widths rather than having a fixed pixel size. Tap targets should meet minimum touch size guidelines of 44px x 44px. Search should have priority placement in mobile menus rather than being buried under hamburger menus. Adjust styling and spacing to account for thicker fingers on touchscreens.

Any search suggestions and results must also remain legible and functional in mobile views. For sticky headers with search, test that scrolling interacts properly without content overlay issues. By thoroughly auditing for mobile-specific concerns, the search experience can be seamless regardless of device. Having convenient search access enhances mobile UX where navigation can often be slower and more difficult.

Installing and Configuring a Craft CMS Search Plugin

Finding and Installing Plugins

The easiest way to find both free and premium search plugins for Craft CMS is through the official Craft Plugin Store. All plugins in the store are tested and verified compatible with Craft.

To install a plugin like Solr, Algolia or MeiliSearch from the store, purchase or download the free version and you will receive a ZIP file. In your Craft CMS admin, go to Settings -> Plugins and upload the ZIP. The plugin and any dependencies will automatically install.

Alternatively, plugins can be found on GitHub or the developer's site. The download will again be a ZIP to upload into Craft. Be aware that plugins from outside the official store may not be fully tested or supported.

Once uploaded and installed, the plugin should appear in the list of installed plugins in Craft ready to be configured. Pay attention to any installation instructions provided with the download as some plugins require additional steps.

Configuring Plugin Settings

After installing, each search plugin will have its own dashboard in Craft's admin to manage configurations and settings. Access the plugin settings to connect API keys, configure indexing rules, adjust display options and tune relevance.

Settings vary by plugin but may include:

  • Selecting which content types, fields and properties to index

  • Setting reindex frequency to keep search results current

  • Choosing which attributes impact result ranking and weighting

  • Enabling synonyms, stemming and other language features

  • Configuring additional display elements like filters and facets

  • Fine tuning performance and resources for optimal indexing

  • Connecting API keys for any required external services

Use the developer documentation for the plugin to understand how each setting impacts search behavior and performance. Adjust based on your specific site goals.

Troubleshooting Installation and Configuration

Common issues encountered when installing and configuring search plugins include:

  • Upload size restrictions - Adjust PHP settings if the ZIP exceeds limits

  • Permissions problems - Check the Craft and plugins folders have proper write permissions

  • Dependencies missing - Plugin may require other plugins to work

  • API connections failing - Doublecheck API keys and credentials

  • Indexing errors - Review plugin logs for clues on failure causes

  • No results displaying - Flush caches and verify indexing is successfully occurring

First steps are checking any error logs in Craft or the plugin itself for details on what's failing. Google the specific error message for common fixes. Ensure any integration credentials are valid and environments match.

If troubleshooting yourself is not revealing the issue, don't hesitate to reach out to the plugin developer/support team through their site or Github issues. The cause of the problem is likely something they have encountered and can quickly identify based on experience.

Take advantage of knowledge bases and troubleshooting guides on plugin sites as well. With a systematic approach to isolating the cause, most installation and configuration problems can be smoothly resolved.

Indexing Content for Search in Craft CMS

Identifying and Mapping Content

The first step in enabling robust search for a Craft CMS website is identifying the types of content that should be indexed by the search engine and mapping them correctly. This mapping includes primary content such as entries, which are the main pages and articles that need to be searchable. It also involves categories and tags, which are useful for filtering and faceted search capabilities.

Assets like images, documents and files need to be indexed to make them discoverable. E-commerce stores will want to map products so customers can search the inventory. User profiles can be enabled in search results as well. And custom fields can be selectively chosen to include only desired data in the index, avoiding bloat.

The search plugin will integrate tightly with Craft's content API and provide an interface to pick and choose what content gets mapped for indexing based on how the site architecture is setup. Additional rules can also be created to precisely control what gets indexed from various content types and avoid indexing any unwanted data. The search index can be configured to automatically update on a schedule or trigger manually whenever needed.

Crawling URLs and Optimization

In addition to mapping content correctly, search also relies on the engine properly crawling all the site's pages to build out a comprehensive index. Most plugins will integrate with Craft's template routing to identify URLs that need to be crawled.

However, large and complex sites may need some tweaks for ideal crawling. This includes avoiding crawling pages like shopping carts, checkouts and confirmation pages that have mainly dynamic content. Adding a rel="nofollow" to certain links indicates they should not be crawled and indexed. Proper use of headers like noindex and nofollow should be ensured as well.

Any crawling errors reported in search console should be fixed. And pages should be optimized for parsing important content in titles, schema and other aspects. With the proper URL discovery and content optimization in place, the search crawler can build the fullest index to power stellar search capabilities.

Using Sitemaps for Indexing

A sitemap XML file serves to guide search engines in properly crawling and indexing all of a site's pages. It contains a structured reference list of all URLs on the site. Craft CMS has native support for generating a sitemap feed that can be consumed by search engines. It is accessed at the /sitemap.xml path. To leverage it, the sitemaps feature must be enabled under Settings -> Sites in the Craft admin.

Any custom elements to include can be selected, and the frequency of updates can be set based on how often content changes. The sitemap URL should then be registered within search engine accounts. The sitemap works hand in hand with content mapping in the search plugin to ensure the index stays completely in sync with the latest content.

For very large sites, plugins are available to generate sitemaps split across multiple files as needed. Having a comprehensive and optimal sitemap significantly improves indexing coverage and efficiency for the best search experience on Craft CMS websites.

Managing Relevance and Boosting Key Pages

Improving Result Relevance

Optimizing search result relevance involves both technical configuration and content tuning. Steps to improve relevance include:

  • Target key terms and topics during content creation. Organize pages around specific subjects rather than generic content.

  • Structure content using titles, headings and meta descriptions that match searcher intent and language.

  • Enhance page relevance through internal links to and from related topics. Cross-linking improves contextual signals.

  • Add schema markup for page types, products, events etc. This provides structured data for accurate indexing.

  • Configure the search engine settings to weight title, content, tags etc as needed per site goals.

  • Create rules to boost fresh or highly-linked content that should rank higher in results.

  • Use the search analytics within plugins to identify queries that lack relevance and optimize accordingly.

Continually refine both content and configuration to provide users with highly relevant results tailored to search intent.

Boosting Key Pages

Most search plugins provide tools to manually control the ranking of specific pages in results through boosting. This elevates pages regardless of other ranking factors.

Reasons for boosting pages include:

  • Homepage - Ensuring the homepage ranks first for branded queries.

  • Product or category - Boost key product or service pages higher.

  • Campaign pages - Prioritizing important marketing pages, announcements etc.

  • Fresh content - Temporarily highlighting new material.

  • Critical info - Urgent info like contact, Covid policies etc.

Boosts are configured within plugin settings on a page-by-page basis. Be selective in use to avoid excessive manipulation of results. Monitor search analytics to judge impact and tweak as needed.

Auto-Suggest and Spell Checking

Auto-suggest provides search term predictions as users type queries. This improves experience by accelerating the path to desired results. As they type “bre”, suggestions like “bread recipe” appear.

Spell checking automatically accounts for misspellings and typos, correcting users' intent. Searching for "accomodation" would still return "accommodation" results for example.

Both features enhance the experience when searchers do not exactly match anticipated queries or terms. Auto-suggest seamlessly guides them to relevant content quickly. Spell checking avoids the frustration of zero results due to simple errors.

For maximum relevance, configure search plugins to enable auto-complete suggestions after 2+ characters are entered. Enable fuzzy matching with a tolerance for small misspellings and typos. Test searches for high traffic queries to ensure suggestions and spell checking produce optimal results.

Implementing Search Analytics and Tracking

Search Usage Reporting

Robust search analytics reporting provides invaluable visibility into how site search is performing. Rather than guesses, data reveals the true search metrics to focus optimizations on. Key metrics to track in search analytics include total search volume over time, which shows engagement levels and growth opportunities. Monitoring popular query terms identifies common keywords that content can be optimized around for ideal targeting.

Tracking queries that return zero results is crucial for uncovering content gaps that need to be filled. Analyzing filter and facet usage can point to areas where result relevance could be improved. Top ranking pages indicate strong search real estate to build upon, while pages that lead to exits signal low quality or relevance content. And tracking overall search response times helps pinpoint performance issues needing attention.

Search plugins integrate tightly with Craft CMS's Google Analytics capabilities to provide detailed reporting on all aspects of usage. Admin dashboards within the plugin give an overview snapshot, while exporting allows more in-depth analysis and manipulation. By continuously monitoring and acting upon the metrics and insights revealed through analytics, search optimization becomes an ongoing process of incremental gains rather than guesswork.

Improving Search Performance

There is truth in the motto "what gets measured gets improved". Search analytics provides the necessary visibility to truly enhance performance rather than blind testing.

Analyzing the metrics reveals concrete opportunities to optimize, such as editing pages to better target frequently searched terms and keywords, identifying needed content gaps based on queries that lack good results, adding synonyms to improve results for common misspellings and word variations, re-weighting factors like freshness in the ranking algorithm if certain topics would benefit, addressing technical slowdowns that hamper response times, and adjusting custom boosts and rules to limit exits and low relevance results.

With data-driven insights, search optimizations can be validated and iterated upon for measurable improvements.

Tracking Search Keywords and Trends

Search keywords and trends naturally evolve over time. By tracking analytics historically over months or years, insights can be gained into how searcher behavior and expectations change and develop.

Plugins can capture extensive search query data, with longitudinal views revealing patterns such as new keywords and topics gaining prominence that should be targeted and optimized for. Data may uncover query patterns highly specific to certain seasons, events or industry trends that warrant tailored content. Interest spikes around current news can be spotted, that temporary or evergreen content could be crafted to satisfy. The impact of new product launches on existing search behavior might be analyzed over time as well. Tracking also identifies keywords that have lost steam and are becoming less relevant to optimize around.

With continual tracking, a rich dataset is built up to analyze genuine user search tendencies rather than relying on assumptions. Useful insights like rising comparisons queries and declining interests by topic can be acted upon to keep search closely aligned with real user needs.

Improving User Experience with Site Search

Search Suggestions and Predictions

Auto-suggestions enhance user experience by providing relevant recommendations as searchers type queries. As they enter "red snea...", suggestions like "red sneakers" and "red sneakers for men" appear.

This predicts the full phrase being sought and accelerates finding the right results. Rather than submitting a full query, users can simply select a suggestion.

Predictive results go a step further to intelligently serve applicable content even for inaccurate queries. Searching "sreandaers" would still show "sneakers" results thanks to predictive technology.

To enable, configure suggestions after two or more entered characters. Set a low threshold for fuzzy matching and typo tolerance to power predictions. Test core queries to ensure optimal suggestions and intent predictions.

Advanced Filtering and Facets

Allow users to refine results by implementing:

  • Filtering - Narrow results by attributes like price, color, category etc.

  • Faceting - Display and filter values like brands, product types, topics.

  • Drill-downs - Progressively narrow within facets by sub-categories and nested values.

These tools divide searchers from merely generic results into precisely relevant subsets tailored to their needs.

Seeking "coffee makers" leads to 1000s of listings. Adding filters for "Under $50" and "Capsule compatible" delivers the perfect concise result set.

Ensure facets and filters reflect important attributes and categories within site content. Test searching across facets for gaps and relevance. Add missing dimensions that would aid users.

Location-Based and Personalized Search

For sites like stores and events, tailor search by location and personalization.

Location-aware results serve nearby content for queries like "pizza places near me". Geolocate users or allow manual entry of a location.

Personalization provides results tuned to the individual’s history and profile like past searches, viewed products, role etc.

Enable location services and profiles within search plugins to provide the layer of context that takes search from generic to ultra-relevant.

Test location and personalization with real user data to identify improvements. Are radius distances optimal? Does personalization reliably weight history and interests?

Refine over time as more behavioural data leads to deeper personalization. Take search from one-size-fits-all to a custom experience for each user.

Shape April 2022 HR 202
Andy Golpys
- Author

Andy has scaled multiple businesses and is a big believer in Craft CMS as a tool that benefits both Designer, Developer and Client. 

Show us some love
Email Us
We usually reply within 72 hours
Agency Directory
Submit your agency
Affiliate Partners
Let's chat