Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

How to Add a Search Form in a WordPress Post

Want to boost engagement on your WordPress blog?

Adding a search form inside your posts might seem unusual, but it’s surprisingly effective, especially for content-heavy sites like online magazines.

Instead of relying solely on a header or sidebar search bar, placing one within your content encourages readers to keep exploring. It’s a small change that can lead to longer sessions and more page views.

In this guide, we’ll show you step-by-step how to add a search form to your WordPress post, no matter which theme you’re using. Let’s dive in!

How to Add Search Form in Your Post with a WordPress Search Shortcode

Why Add a Search Form to Your WordPress Posts?

If visitors enjoy a post on your WordPress website, they’re likely to want to read more. By adding a search form to a post, you can help visitors find more blogs they’re interested in reading.

In this way, you can increase your pageviews and reduce your bounce rate.

The longer visitors stay on your website, the greater the chance they’ll join your email list, leave a comment, make a purchase, follow you on social media, or take other positive actions.

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

Having said that, we’ll share three methods for how to add a search form in a WordPress post. Just use the quick links below to jump straight to the method you want to use:

Let’s get started.

Method 1. Add a Search Form in a WordPress Post (Works With Any Theme)

The simplest way to add a search form to your posts is by using the built-in Search block.

A search bar in a WordPress post

In this guide, we’ll show you how to add the block to a post, but you can also add it to any page or widget-ready area of your site.

We also recommend adding this at the bottom of your post to avoid disrupting the reading experience.

To get started, simply open the page where you want to add a search form. In the WordPress block editor, click on the + icon.

In the popup, type in ‘Search.’ When the right block appears, click to add it to the page.

Adding the search block to a WordPress post

By default, the block uses ‘Search’ for both its label and the button text. This text will be visible to visitors, so you may want to replace it with something more descriptive.

For example, if you’re adding the search bar to a WordPress blog, then you might want to use ‘Search recent blog posts’ or similar.

Changing the search bar heading

You can even use the label and button text to motivate your visitors.

For example, if you’ve created an online store, then you might use something like ‘Find more great deals’ or ‘Search for similar offers’ for your product search form.

You can also add some placeholder text. This text will disappear automatically when the visitor starts typing.

To add a placeholder, simply click on ‘Optional placeholder…’ and then start typing.

Adding a placeholder to the WordPress search bar

By default, WordPress will use your theme to style the search bar.

However, you can change the button’s background and text color using the ‘Color’ settings in the right-hand menu. This can help your search bar stand out from the rest of your site.

Customizing the WordPress search button in a post

When you’re happy with how the Search block looks, you can go ahead and either publish or update the post. If you visit your site, you’ll now see the search bar within the post’s content.

You can add a search form to more WordPress posts and pages following the same process above. For detailed instructions on how to add the Search bar to a sidebar or similar section, please see our guide on how to add and use widgets in WordPress.

Method 2. Add a Search Form to All WordPress Posts (Block-Based Themes)

If you’re using a block-based theme such as ThemeIsle Hestia Pro, then you can add a search bar to the template that WordPress uses for all your blog posts.

In this way, you can quickly and easily add a search bar to every single blog post across your entire WordPress website.

To open the full-site editor, go to Themes » Editor in the WordPress dashboard.

Adding live Ajax search using the full-site editor (FSE)

By default, the full site editor shows your theme’s home template.

To see all the available options, select ‘Templates’ from the left-hand menu.

Adding a search form to a WordPress blog using the FSE

This shows a list of all the templates that make up your WordPress theme.

To customize the blog template, go ahead and click on ‘Single.’

Adding a search form to a WordPress blog using the full-site editor

WordPress will now show a preview of the blog layout.

To go ahead and edit this template, click on the small pencil icon.

Adding a search form to a WordPress blog using the full-site editor

You will now see this template in the full-site editor.

To go ahead and add a search bar, click on the blue ‘+’ icon.

Adding a search bar to a WordPress blog template

In the popup that appears, type in ‘Search’ to find the right block.

You can now drag the block to the location where you want to show the search bar.

Adding a search block using the WordPress full-site editor

To customize the block title or placeholder text, simply type the new messaging into the search block.

When you’re happy with how the block looks, click on ‘Save’ to make the search bar live.

Customizing the search bar using the full-site editor (FSE)

Now, if you visit any blog post on your site, you’ll see the search bar.

Method 3. Add a Search Bar to All WordPress Posts With Code (Works With Any Theme)

If you don’t use a block theme but still want the search bar to appear in all of your posts, then you will need to use code.

To do this, we recommend using WPCode. This code snippet plugin makes it safe and easy to insert custom code into your theme files without directly editing them. This way, you can add various code snippets without breaking your website.

Some of our partner brands actually use WPCode to add and manage custom code snippets. We’ve also tested it extensively, and you can see our findings in our detailed WPCode review.

What you want to do is install the WPCode plugin in WordPress. You can read our step-by-step guide on how to install a WordPress plugin for more information.

Then, go to Code Snippets » + Add Snippet. Select ‘Add Your Custom Code (New Snippet)’ and click the ‘Use snippet’ button.

Choose 'Add Your Custom Code (New Snippet)' option

Now, give your new custom code a name. It can be something simple like ‘Search Bar on Blog Posts.’

After that, change the Code Type to ‘PHP Snippet.’

Adding a search bar to blog posts with WPCode

Then, in the Code Preview box, copy and paste the following code snippet:

// Define the button text and placeholder text. You can customize these values as needed.
$button_text = 'Search'; // The text displayed on the search button
$placeholder_text = 'What are you looking for?'; // The placeholder text in the search input field

// Construct the search form HTML using the defined button text and placeholder text.
$search_form = '<form role="search" method="get" action="' . esc_url(home_url('/')) . '" class="wp-block-search__button-outside wp-block-search__text-button wp-block-search">
                    <label class="wp-block-search__label" for="wp-block-search__input-2">' . esc_html($button_text) . '</label>
                    <div class="wp-block-search__inside-wrapper ">
                        <input class="wp-block-search__input" id="wp-block-search__input-2" placeholder="' . esc_attr($placeholder_text) . '" value="" type="search" name="s" required="">
                        <button aria-label="' . esc_attr($button_text) . '" class="wp-block-search__button wp-element-button" type="submit">' . esc_html($button_text) . '</button>
                    </div>
                </form>';

// Output the search form HTML.
echo $search_form;

This code will add a basic search bar similar to the search block. You can customize the button and placeholder text as needed.

Once done, scroll down and make sure ‘Auto Insert’ is selected for the Insert Method.

For the Location, navigate to the ‘Page-Specific’ tab and choose the one that best suits your criteria. For the sake of example, we’ve chosen ‘Insert After Content.’

Choosing Insert After Content in WPCode

When you are done, just make the code ‘Active’ and click ‘Save Snippet.’

You should now see something like this:

Example of a search bar added with WPCode

The Search block uses WordPress’ built-in search feature. However, this is quite limited and not very good at showing accurate results.

In some cases, you may want your WordPress search feature to be more advanced. Perhaps you want to add a search-by-category function or make your blog post comments searchable.

That’s where SearchWP comes in. This custom search plugin gives you complete control over the WordPress site search so you can deliver more accurate results to your visitors.

SearchWP also makes all parts of your site searchable, including PDF files, ACF files, text files, WordPress custom fields, and more. You can check out our full SearchWP review to learn all its features.

After creating a custom search form, you can add it to any part of your website using either a block or a shortcode.

Adding an advanced search form to a website or blog

To learn more, please see our guide on how to improve WordPress search with SearchWP.

FAQs About Adding a Search Form in WordPress

After understanding the benefits and various methods of adding a search form to your WordPress posts, you might have some lingering questions. Below, we address some common inquiries to help you get the most out of this strategy.

Why would I want to add a search form inside a blog post?

Adding a search form directly in your posts makes it super easy for readers to discover more of your content, right when they’re most engaged. It’s a smart way to increase page views and keep people on your site longer.

Can I make the search form match my site’s style?

Absolutely! Most WordPress plugins let you tweak things like colors, placeholder text, and labels so the form blends in perfectly with your design.

What if I’m not using the block editor?

No worries. If your theme doesn’t support block-based editing, you can still add a search form using custom code. A plugin like WPCode makes it easy and safe to drop those snippets into your site.

How can I tell if my search form is actually working?

You can track performance using tools like Google Analytics. Keep an eye on metrics like time on site and page views per session. If they go up, your in-post search form is doing its job!

We hope this tutorial helped you learn how to add a search form in a WordPress post. You may also want to learn how to create a contact form in WordPress or check out our expert picks of the best conditional logic plugins for WordPress.

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

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

34 CommentsLeave a Reply

  1. Thank you for the great tip. I have a search bar in the header, but the downside is that when reading an article and scrolling down, the header is no longer visible because it’s not fixed. As a result, most users had to scroll back up to see the search form. Following your advice, I’ve now added the search form to the end of each article and will be measuring whether this increases the number of pages viewed per session. I think this is a really simple yet effective trick. Great idea!

  2. Thank you, but I’m seeing only {wpbsearch] on the page I want the search form to be. I’m not sure if I’m placing the add_shortcode(‘wpbsearch’, ‘get_search_form’); code in the correct place in the theme functions.php file. I placed the following code in a perceived function location: between /** and * is_it woocommerce_page- Returns true if on a page which uses WooCommerce…) in the actual page I want to search, as I want it to be a page-only search, (and is this the correct code to do that?)

    The Page Code:
    function wpbsearchform( $form ) {

    $form = ‘

    ‘ .
    _(‘Search Timeline For:’) . ‘

    ‘;

    return $form;
    }

    add_shortcode(‘wpbsearch’, ‘wpbsearchform’);

  3. thank you so much for this. It was so easy. I have been searching for how to do this for months but was looking in the wrong places.

  4. I want to add a general google search bar -not custom search just a general google search box so users will not have to leave the page to conduct a google search.

  5. Hi there!
    You guys are really the best (y)
    Great post once again.
    I’ve been able to add the search form with visual composer as well. So, maybe someone will give it a try :)

    Finaly, I’m trying to add a search form in a slideshow like this site:

    I’ll be more than glad if someone here do have a trick for this.

    Thanks again and stay blessed

  6. Just what I was looking for, thank you! What would an example be of CSS if we wanted to change the colors and text of the search bar? (i.e. what would we add to CSS to change the colors/text/etc.)?

  7. This was stupid easy to implement. I wrote it as a plugin so I can use on MultiSite :) Thank you for the write-up.

  8. Hello,

    Is it possible to make this search form to search only a particular category?

    Example. I have 5 Categories – Cat 1, Cat 2, Cat 3, Cat 4 and Cat 5.

    I want the search from only on page 4 and the search form should search only from Cat 3?

    Thanks
    Sakthi

  9. Hi,
    really love your tutorials!

    Is it possible to define the search for comments within each post I put the shortcode? So that it’s not a global search, but a search of the comments just of the post I’m searching at via the shortcode. Would be amazing for helping me out, don’t find anything.

    Thanks!!

  10. Hi, I have just used this script on my theme. Thanks for the help. And its working. But i have one problem, I want to edit the title of that search form how to do. Please help me out.

    Thanks
    Sandeep Kumar Dan

  11. Awesome tip! Thanks for posting, it is just what I was looking for. I wanted something simple so that people can search through exercise videos and this fit the bill.

  12. Great article! I created a short code and then tweaked the CSS to position and size it the way I wanted.

    add_shortcode(‘prodSearch’, function($atts) {
    global $woocommerce;

    echo ”;
    get_product_search_form();
    echo ”;

    });

    • Greg… what was your custom form code for your woocommerce search form you mention here?

      I am trying to get two search boxes into a top navigation one for standard wordpress site search the other for woocommerce products..

    • Hi Greg!
      Thank you for this tip!.. Do you know how to change the search box text and css for this shortcode??
      Any help would be greatly appreciated..
      -Justin

  13. Just used it in my WP site. Was able to add search box anywhere I like.

    Thank you! This one’s simpler and easy to use compared to the plugins out there.

  14. Great little tutorial. I tried to embed this shortcode within a column shortcode, but it just appears at the top of the page, instead of within the column. Is there something I need to add?

  15. i read your site everytime when you put something new. I want to know if is posible to put search form for my site..like google search..Now i used search default from wordpress but i dont like very good the results and i want to know if is posible to put “google search” just for my content. i hope you understand, i try to write correct english but i’m not so good. i wait your answer if is posible. i appreciate your site and your work.

  16. Hi,

    Thank you for the tip .
    Don’t forget to use different IDs to avoid duplication of FOR and ID’s values.
    Here you use exactly the same as default WordPress’ search form.

    Thank you,
    Regards,
    G.

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.