Beginner's Guide for WordPress / Start your WordPress Blog in minutes

How to Add a Search Form in a WordPress Post

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

By adding a search bar to your post’s content, you can help visitors find more great content and keep them on your site for longer.

In this article, we’ll show you how to add a search form in a WordPress post.

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

Why Add a Search Form to Your Posts and Pages?

If a visitor has enjoyed a post on your WordPress website, then they will likely want to read more. By adding a search form to a post you can help visitors find more content that they’re interested in reading.

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

Visitors will also be more likely to join your email list, leave a comment, make a purchase, and follow you on social media if they stay on your site for longer.

In this guide, 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.

Having said that, let’s take a look at how to easily add a search form in a WordPress post.

How to Add a Search Form in a WordPress Post

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 any post, but you can also add it to any page or widget-ready area of your site.

To get started, simply open the page where you want to add a search form and then click on the + icon.

In the popup that appears, type ‘Search’ to find the right block. Once you click on the Search block, it will add the block to your 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 run an online store then you might use something like ‘Find more great deals’ or ‘Search for similar offers.’

You can also add some placeholder text to the search bar. 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 following the same process above.

How to Improve WordPress Search

The Search block uses WordPress’ built-in search feature. However, this is quite limited and not very good in finding the relevant content.

That’s where SearchWP comes in.

SearchWP is the best custom search plugin for WordPress. It 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.

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

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 pick of the best email marketing services for small businesses.

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.

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

33 CommentsLeave a Reply

  1. 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’);

  2. 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.

  3. 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.

  4. 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

  5. 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.)?

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

  7. 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?


  8. 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.


  9. 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.

    Sandeep Kumar Dan

  10. 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.

  11. 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 ”;
    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..

  12. 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.

  13. 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?

  14. i read your site everytime when you put something new. I want to know if is posible to put search form for my 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.

  15. 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,

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.