How to Add a Search Form in a WordPress Post With a Shortcode

Not including a search option on a website is a typical error many websites fail to correct. This can be a rather huge issue, especially for eCommerce and websites whose sole purpose is delivering some type of content. For the first, search is a central point for visitors to find the right products. And, is surely a huge flaw once a website starts growing in size. For the second, it will be difficult to find news and information, especially after a while, when the number of posts and pages starts to pile up. Failing to meet these requirements can easily fend off visitors, negatively affect overall engagement, and deteriorate the overall usability of a website. Whether you are expecting visitors to make a purchase, subscribe, leave a comment, or simply look for information, WP Full Care recommends you to add a search form in a WordPress post with a shortcode. Or, at least, by using some of the search plugins that allow the search functionality.

Why you should add a search form to a WordPress website?

When you look at the overall internet experience, it’s clear that “searching” is at its core. All information people are looking for today is filtered and displayed through some kind of search. Why would it be any different with websites, pages, and posts? Basically, search bars and forms are what allow website visitors to start looking for information, the moment they land on your pages. If they are denied this option, they, in essence, have no other choice but to leave the website.

Searching for a product on a website while holding a credit card.
If people don’t have an option to search your website, they will quickly look for products elsewhere.

Besides, a search form is not useful only from the visitors’ standpoint. There are a few reasons website owners benefit from it:

  • A search form can help you discover new keywords – by following what visitors are typing in a search form, you can see what is in demand and what are their preferences. You can use this information to modify your website offer, regardless of whether you are offering products or just information.
  • It improves the overall user experience and helps you with search engine optimization – the search functionality itself is essential for a better user experience. As a result, it will help you boost your SEO efforts and help you rank higher.
  • Allows you to make adjustments that will improve conversions – insights you get from search forms will help you maximize the conversion rates by knowing exactly what steps to take to optimize your website properly.
  • Help you with data management – for example, by adding tags on posts, which will lead to better classification and information serving.

A few ways to add a search form in a WordPress post

In general, there are two most common ways to add a search form in WordPress posts, pages, or a website in its entirety:

  1. Add a search form in a WordPress with code
  2. Add a search form in a WordPress with plugins

1. Add a search form in a WordPress with code

For several reasons, this is probably the best way to add a search form. Too many plugins on a website can eventually affect its performance. However, it’s not exactly a beginner-friendly method. The best way to add a code to your website is to have experienced WordPress developers assist you. Mostly because the first step here is to edit the Theme Functions (functions.php) file.

Inside the functions.php file, it’s necessary to add the next line of code:

add_shortcode(‘wpbsearch’, ‘get_search_form’);

Instructions on where to copy the search form code in WordPress.
Remember to properly place the code right below the “script” tag.

Once you are done editing your functions.php, it will add a default-looking search form wherever you place [wpbsearch] on a page.

Adding a custom search form

If you are not satisfied with the default search form appearance, you can add custom search form. In that case the code will look like this:

function wpbsearchform( $form ) {

$form = ‘<form role=”search” method=”get” id=”searchform” action=”‘ . home_url( ‘/’ ) . ‘” >
<div><label class=”screen-reader-text” for=”s”>’ . __(‘Search for:’) . ‘</label>
<input type=”text” value=”‘ . get_search_query() . ‘” name=”s” id=”s” />
<input type=”submit” id=”searchsubmit” value=”‘. esc_attr__(‘Search’) .'” />

return $form;

add_shortcode(‘wpbsearch’, ‘wpbsearchform’);

Remember, this method requires you to add a shortcode on every page and post you want it to appear. However, if you add the shortcode on the top-bar, or sidebar, it will display the search form on all pages.

2. Add a search form in a WordPress with plugins

If you are a beginner, probably the easiest way to add a search form is by using one of the search plugins. SearchWP Live Ajax Search, SearchWP Modal Search Form, Ivory Search, and FiboSearch are just some of the examples.

Using simple plugin solutions

If you are using Ivory Search, adding a search form is pretty straightforward:

Once you install and activate the plugin, all you have to do is to go to the “Ivory Search” plugin option, which will appear on your WordPress sidebar. Hover over it and select the “Search Forms” sub-option.

There, the plugin will provide you with a shortcode:

[ivory-search id=”10980″ title=”Default Search Form”]

Basically, you can copy this line of code wherever you wish your default search form to appear.

Ivory search form options with a WordPress shortcode.
Experiment with options until you get the right search form for your pages.

If you prefer widgets, SearchWP Live Ajax Search is an alternative worth checking out.

SearchWP – for more robust search forms

For those who are in need of more complex and customizable search options, the SearchWP plugin can be a good choice. However, it’s a premium search plugin that requires some knowledge to set up.

The first step is to install and activate the SearchWP plugin. Then, you will need the license key from your account, which you will enter in the “License” plugin option. After activation, it will be necessary to configure search engine settings.

The second step is to download and install SearchWP Shortcode Extension the same way you would install any other plugin. And, of course, activate it.

Finally, once all previous steps are complete, you are able to add a new custom search form to your pages by using blocks. However, there is a caveat here: You will need to set the block to be a “Custom HTML” block to use it correctly. Only then you will be able to add and use the next shortcode:


<div class=”search-results-wrapper”>

<div class=”search-results-pagination”>
[searchwp_search_results_pagination direction=”prev” link_text=”Previous”]
[searchwp_search_results_pagination direction=”next” link_text=”Next”]

In general, this will add the search form to your page or post, and display the results on several pages, if necessary. Remember here to pay close attention to 404 pages and set all redirections properly so visitors don’t miss the content.

Using a search form in WordPress becomes an unavoidable necessity for every modern website. As the general content is increasing in amount, the need for a way to search throughout the content becomes irreplaceable. With features like this, not only you are improving your website usability for visitors, but for yourself as well. As a result, your posts and pages will find their way to the right visitors’ eyes. This will eventually lead to better ranking results and an increase in general conversion rates.

404 error404 pageabove the foldadvanced cssAIDA modelakismet pluginbacklinks auditbehavior patternbounce ratebrowser compatibilitybulk deletecaching pluginscall-to-actionchild themecode snippetcolor schemecomment sectioncompetitors' backlinkscontact formconversion ratecreate child themeCTA buttoncustom pagecustom themedead linksdefault configurationdigital marketingdomain authorityeasy manageedit main pageediting toolsemail marketingengaging contentFAQ pluginsfilter spamfix site errorfolder structurefree pluginsfriendly toneGoogle analyticsgoogle rankingsGravity Forms pluginguest postingHeadless WordPressHow toimage optimizationincrease readabilityindex errorsinfluencer marketingkeyword researchlibrary assistantlink managementlink trackingloading speedlocal businesseslong-tail keywordsmedia replacemedia restrictionmobile optimizationmoney onlinemulti currency pluginsmysql queryonline presenceonline validatorpage builderpage creationpopup pluginproducts and servicesquality imagesquality serviceReact JSreaction buttonsredirect chainsresponsive designschema markupsearch rankingsearch termsSEO for bloggersSEO optimizationSEO professionalsSEO tipsSEO toolsshort linkssocial mediasocial media plugins for WordPressssh commandsstatic pagetargeted audiencetechnical performancetest metrictext formattheme setting uptime utilizationtips and trickstraffic increaseunique visitorsuser accessuser engagementuser experiencevisual designvisual elementsvisual reportweb crawlersweb hostingwebsite architecturewebsite auditwebsite designwebsite elementswebsite maintenancewebsite optimizationWebsite problemswebsite securitywebsite structureWhat’s new in WordPresswhite spacewoocommercewordpressWordPress admin email verification noticeWordPress debug modeWordPress functionalityWordPress pluginWordPress pluginsWordPress recovery modeWordPress responsive designwordpress securitywordpress themewordpress theme editwordpress tipsWordPress tips and tricksWordPress web hostingwp security