If this tutorial is not what you were looking for, you still have any questions, suggestions or concerns - feel free to let us know. Please help us to serve you better!

Your Name

Your Email

Your Message (required)

captcha

Featured templates

WordPress. How to add a search form and edit search results page

This tutorial is going to show you how to add a search form & edit search results page on your WordPress template.

How to add a search form

Log into your WordPress admin panel and go to the left-side menu Appearance -> Widgets.

  1. Under the Available Widgets locate a one called Search (A search form for your site) and drag it to one of the boxes available on the right side (depends on the particular template design)
  2. When needed, specify a title for your Search form and click Save.
  3. Preview the page which has the widget position with the Search form enabled to see it there.

How to edit the search results page

  1. In your WordPress admin panel go to Appearance -> Editor.
  2. From the right-hand side of the Edit Themes page look for the one called Search Results (serach.php) and click on it. The search.php is a template file that represents a template that displays the search results.

  3. Search Form (searchform.php) you can also select from the right side represents another template file that is often included to the sidebar of many themes and generates the search box form. If there isn’t one in your theme, you can easily copy it from the Default theme.
  4. Prior to making any changes to the code of these pages, we suggest that you copy it and save in a file on your computer to have for a backup copy.
  5. The way you need to customize the search results page is totally up to you. For instance, your default search results pages look like this:
  6. You can look for the text you see on this page (like: Search for, Read More, Older Entries, Newer Entries etc) in the code by hitting Ctrl + F.
  7. To disable text, for example, the one that says No comments, first look for the text with Ctrl + F to find the line it is in, which is
    <?php comments_popup_link('No comments', '1  comment', '% comments', 'comments-link', 'Comments are closed');  ?>

    And delete it (comment it out).

  8. To change the number of search results, put
    <?php query_posts('showposts=#'); ?>

    above

     <?php if (have_posts()) : while  (have_posts()) : the_post(); ?>

    where # is the number of posts.
    To remove the footer sidebar, remove <?php get_footer(); ?> at the bottom.

  9. To display the number of results, change
    <h1>Search for: "<?php the_search_query();  ?>"</h1>

    to

    <h1>Search for: "<?php /*  Search Count */ $allsearch = &new  WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1);  $count = $allsearch->post_count; _e(''); _e('<span  class="search-terms">'); echo $key; _e('</span>'); _e(' —  '); echo $count . ' '; _e('articles'); wp_reset_query(); ?></h1>
  10. Once you are done with your changes, click on Update File at the bottom to save them and try use the Search box on your site:

Feel free to check the detailed video tutorial below:

WordPress. How to add a search form and edit search results page

WordPress. How to add a search form and edit search results page, 5.0 out of 5 based on 1 rating