How to Add a Search Form in a WordPress Post With a Shortcode – Website Tips

Curated by WorkingFromHome

This article is an excerpt from the original article found in the Read More link – please follow for full article.

Do you want to add a search form to a WordPress post?

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

In this article, we’ll show you how to add a search form in your posts and pages using a WordPress search shortcode.

Why Add a Search Form to Your Posts and Pages?

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

When you make it easy for users to spend more time on your website, you can increase your pageviews and reduce your bounce rate.

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

In this tutorial, we’ll show you how to add the standard WordPress search form to your posts. If you want to add a custom search form, then see our step by step guide on how to create a custom WordPress search form.

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

Method 1: Adding a Search Form with a Plugin

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

Setting Up SearchWP

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.

Upon activation, you need to visit the Settings » SearchWP page and then click on the ‘License’ menu option.

You then need to enter your license key in the License box. You can find this information in your account on the SearchWP website. After that, you should click the Activate button.

Next, you need to click on the Engines menu option. This brings you to a screen where you can choose your search engine settings.

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

The Attribute 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.

After you’ve finished adjusting the settings, make 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 post search form to WordPress.

You’ll need to visit the SearchWP Shortcodes Extension website and then click the ‘Download available with active license’ button.

After that, you need to install and activate the extension the same way you installed the plugin above. Now you can add a search form in your posts.

Simply edit the post and place your cursor where you want to add the search form. After that, click the plus ‘Add Block’ icon to bring up the blocks menu.

Next, type ‘html’ into the search box. Then, select the ‘Custom HTML’ block.

Once you’ve added the new block, you can add the following shortcodes and HTML to your page. If you need more help, then 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 will add a search form to the post, create a section to display the search results, show a no results message if necessary, and add pagination if the results go into multiple pages.

Make sure you click Publish or Update to save your post and make it live.

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

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

Method 2: Adding a Search Form Using Code

You can also add a search form to your WordPress posts by use of a code snippet. This method is not recommended for beginners, so if you’re not familiar with code, then you should use Method 1 instead.

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

If you have not edited the functions.php file before, then take a look at our beginner’s guide on pasting snippets from the web into 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'); 

Here is how it looks on our demo website when using the WordPress Theme Editor to add the snippet to the Twenty Twenty-One theme’s functions.php file.

After that, you simply add the shortcode [wpbsearch] to the post or page where you would like the search form to appear.

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

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

 function wpbsearchform( $form ) {        $form = '';        return $form; }    add_shortcode('wpbsearch', 

For the Full Article
Please Continue Reading Here: How to Add a Search Form in a WordPress Post With a Shortcode

Commentary:
Really helpful news and links can be found on this full article.
source – WPBeginner.com

You May Also Like…

How to Properly Rename Categories in WordPress (Beginner’s Guide) – Website Tips

How to Properly Rename Categories in WordPress (Beginner’s Guide) – Website Tips

Do you need to rename some categories on your WordPress site? As your site grows, you might need to change the name of some of your categories or merge them with other categories. In this article, we will show you how to properly rename categories in WordPress without affecting your SEO strategies. Why Rename Categories in WordPress? If you’ve recently created a WordPress website, then creating a good organizational structure will make it easier for your visitors to find your content and can help your site rank higher in search engine results pages. That’s why WordPress offers categories and tags. You can learn how to organize your content effectively in our guide on best practices for categories and tags. As you add more content, you may wish to improve the way you organize your posts, and you may decide to rename some of your categories. Let’s have a look at…

How to Clear Your Cache in WordPress (Step by Step) – Website Tips

How to Clear Your Cache in WordPress (Step by Step) – Website Tips

Recently, one of our readers asked us how to clear cache in WordPress? Your web browser, hosting server, and caching plugins can all serve cached content which can make it difficult for you to see the changes you made to your website right away. Clearing your WordPress cache is also the first troubleshooting advice that you’ll often hear. In this article, we will show you how to properly clear the cache in WordPress. We’ll cover browser cache, web hosting cache, and top WordPress caching plugins in this guide. What is Caching in WordPress? Caching solutions will store static versions of your website in a cache. This allows WordPress to skip running heavier PHP scripts every time your site loads. The caching process helps to improve WordPress speed and performance, and the overall user experience. Here’s an example of what the caching process looks like: There are several different types of…

Working From Home TV …

Tips to enhance your own website…

How to Properly Rename Categories in WordPress (Beginner’s Guide) – Website Tips

How to Properly Rename Categories in WordPress (Beginner’s Guide) – Website Tips

Do you need to rename some categories on your WordPress site? As your site grows, you might need to change the name of some of your categories or merge them with other categories. In this article, we will show you how to properly rename categories in WordPress without affecting your SEO strategies. Why Rename Categories in WordPress? If you’ve recently created a WordPress website, then creating a good organizational structure will make it easier for your visitors to find your content and can help your site rank higher in search engine results pages. That’s why WordPress offers categories and tags. You can learn how to organize your content effectively in our guide on best practices for categories and tags. As you add more content, you may wish to improve the way you organize your posts, and you may decide to rename some of your categories. Let’s have a look at…

How to Clear Your Cache in WordPress (Step by Step) – Website Tips

How to Clear Your Cache in WordPress (Step by Step) – Website Tips

Recently, one of our readers asked us how to clear cache in WordPress? Your web browser, hosting server, and caching plugins can all serve cached content which can make it difficult for you to see the changes you made to your website right away. Clearing your WordPress cache is also the first troubleshooting advice that you’ll often hear. In this article, we will show you how to properly clear the cache in WordPress. We’ll cover browser cache, web hosting cache, and top WordPress caching plugins in this guide. What is Caching in WordPress? Caching solutions will store static versions of your website in a cache. This allows WordPress to skip running heavier PHP scripts every time your site loads. The caching process helps to improve WordPress speed and performance, and the overall user experience. Here’s an example of what the caching process looks like: There are several different types of…

0 Comments

Submit a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.