Are exchanged or reciprocal links okay with Google?
Etmagnis dis parturient montes, nascetur ridiculus mus. Donec lorem ipsum dolor sit amet, et consectetuer adipiscing elit. Aenean commodo ligula eget consyect etur dolor.

Contact Info

(+888)-123-4587

121 King St, Melbourne VIC 3000, Australia

info@example.com

Folow us on social

How to add a search form to a WordPress post with a shortcode

Want to add a search form to a WordPress post?

Adding a search form to your post or page content is a great way to encourage your visitors to find more content and stay longer on your site.

In this article, we will show you how to add a search form to your posts and pages using a WordPress search card code.

How to add search form to your post with a WordPress search card code

Why add a search form to your posts and pages?

If a visitor enjoyed reading a post on your WordPress blog, they would probably like to read more. Offering a search form in the post will help them find more of your content that they are interested in.

By making it easy for users to spend more time on your site, you can increase your page views and reduce your bounce rate.

Your visitors are also more likely to sign up for your email list, leave a comment, make a purchase and follow you on social media.

In this guide, we will show you how to add the default WordPress search form to your posts. To add a custom search form, see our step-by-step guide on how to create a custom WordPress search form.

We’ll show you two ways to add a search form to your posts, and the first is the simplest. Use the links below to jump to the method you would like to use.

Method 1: Add a search form with a pluginMethod 2: Add a search form using code

Method 1: Add a search form with a plugin

The easiest way to add a search form to your posts is by using the SearchWP plugin. It is the best search plugin for WordPress used by over 30,000 websites.

SearchWP setup

The first thing you need to do is install and activate the plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.

After activation, visit the Settings page »SearchWP and then click on the menu item ‘License’.

Enter SearchWP license key

You must then enter your license key in the License field. You can find this information in your account on the SearchWP website. Then click the Activate button.

Next, click the Engines menu. This brings you to a screen where you can select your search engine settings.

SearchWP engine settings

Here you need to create a search engine on the entire site. You can adjust your search engine settings by clicking the Posts, Pages, and Media drop-down menus.

The Feature Relevance sliders in each section adjust how the search engines value and rank content. For example, if you want to value the post title higher than the content, then you can adjust the sliders accordingly.

Adjust the SearchWP slider settings

When you have finished adjusting the settings, be sure to click the ‘Save Engines’ button to save the default search engine.

Adding a search form to a post

Now you need to download the SearchWP shortcodes extension to easily add your new custom mail search form to WordPress.

You need to visit the SearchWP Shortcodes Extension website and then click on the ‘Download Available with Active License’ button.

Download SearchWP Shortcodes extension

Then install and activate the extension in the same way as you installed the plugin above. Now you can add a search form to your posts.

Simply edit the post and place your cursor where you want to add the search form. Then click on the plus icon ‘Add block’ to bring up the menu of blocks.

Insert a custom HTML block

Then type ‘html’ in the search box. Then select the ‘Custom HTML’ block.

Once you have added the new block, you can add the following shortcodes and HTML to your page. If you need more help, see our guide on how to add a shortcode in WordPress.

[searchwp_search_form]

[searchwp_search_results]

[searchwp_search_result_link]

[searchwp_search_result_excerpt]
[/searchwp_search_results]

[searchwp_search_results_none]

No results found, please search again.
[/searchwp_search_results_none]

[searchwp_search_results_pagination direction="prev" link_text="Previous"]
[searchwp_search_results_pagination direction="next" link_text="Next"]

This code adds a search form to the post, creates a section to display the search results, displays a message with no results if necessary, and adds page layout if the results go into multiple pages.

Be sure to click Publish or Update to save your post and do it live.

Click Publish or Update to save your post

To see the search form in action, simply view the post on your WordPress site. This is how it looks on our demo page, which runs the Twenty Twenty-One theme.

SearchWP Form Preview

For more tips on customizing your search, see our guide on how to improve WordPress search with SearchWP.

Method 2: Add a search form using code

You can also add a search form to your WordPress posts using a snippet of code. This method is not recommended for beginners, so if you are not familiar with code, use method 1 instead.

In this method, you will need to edit your theme’s functions.php file.

If you have not edited the functions.php file before, take a look at our Beginner’s Guide to Inserting Excerpts from the Web in WordPress.

All you have to do is open your theme’s functions.php file or a site-specific plugin and paste the following code:

add_shortcode (‘wpbsearch’, ‘get_search_form’);

This is how it looks on our demo site when you use the WordPress Theme Editor to add the excerpt to the Twenty-One theme’s functions.php file.

Editing functions.php in Theme Editor

Then just add the card code [wpbsearch] to the post or page where you would like the search form to appear.

Search form card code

This will display the default search form. To view the search form, simply view the post on your WordPress website.

Search form preview

If you would like to display a custom search form, use this code instead.

function wpbsearchform ($ form) {$ form = ‘

‘; return $ form; } add_shortcode (‘wpbsearch’, ‘wpbsearchform’);

Feel free to change the code to customize the search form as you wish.

We hope this guide helped you learn how to add a search to your post with a WordPress search card code.

You may also want to learn how to create a free business email address, or see our list of reasons why you should use WordPress for your site.

If you liked this article, please subscribe to our YouTube channel for WordPress video tutorials. You can also find us at Twitter and Facebook.

The Blog post first appeared on WPBeginner.

    Leave Your Comment

    Your email address will not be published.*