wordpress search engine

WordPress Search Page

Rate this article

Share this article

A WordPress search Page is just a page with a custom Page template to give users more information for searching your site. Different WordPress Themes feature different template files. Some include a search.php template file. This is not a Search Page, it is merely a template that displays the search results. There is also a template file called searchform.php. This is a template file that is often included in 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.

wordpress search

This article will cover two things. One is on how you can create a Wordpress search page and the other is on how to create a search results page.

Add a Wordpress search page

Edit the search.php and searchform.php method

  1. Using a text editor, open the page.php and save it as searchpage.php. If you do not have a page.php, you can create one based upon your Theme’s index.php template file.
    Note: The filename search.php is reserved as a special template name, so avoid its usage; the suggested searchpage.php just makes it easy to recognize in the list of files.
  2. After saving it, edit the file:
    1. Delete The Loop (i.e. basically everything within your content div), leaving the div tags intact.
    2. Add a heading such as “Search Posts” or something similar. You can use an existing class from your CSS stylesheet, or create a new one.
    3. Copy the following into the content div or any other div that contains the content of your Page:
       <?php get_search_form(); ?>
    4. At the top of your searchpage.php, before anything else, add this to give your Search Page a heading WordPress will recognize in the Administration Screens:
       * Template Name: Search Page
  3. Save the file
  4. Upload the file to your theme directory (if you made changes to your style.css style sheet file, upload that, too).If you create searchpage.php from page.php in Twenty Seventeen, it would be as follows:
     * Template Name: Search Page
    <?php get_header(); ?>
    <div class="wrap">
        <div id="primary" class="content-area">
            <main id="main" class="site-main" role="main">
            <?php get_search_form(); ?>
            </main><!-- #main -->
        </div><!-- #primary -->
    </div><!-- .wrap -->
    <?php get_footer(); 

    Based on the Search Page Template, we will create the search page.

    1. In the Administration Screen go to Pages > Add New.
    2. In the title field enter Search.
      Do not write anything in the content area.
    3. While still on the same page, look for Page Attributes on the right side menu.
    4. Select the drop-down menu in Template, and select Search Page.
    5. Click the Publish button.

There are several options you can use to customize your internal search results pages. While you could always dive into the search.php code (though this is best left to experienced users comfortable with PHP and CSS coding), there are several plugins you can use to implement similar changes. Finding the functionality that works best will depend on you and your site. Small personal sites may benefit from free plugins, while larger sites might need a premium solution.

To do this manually you will need to start by creating a child theme.

Next, create a search.php file in your brand new child theme and copy over the code from your old theme (you can find this by either opening up these files on your server via FTP, or from your WordPress dashboard under Appearance > Editor > Search.php). Now you can replace the default title in your child theme’s search.php with the following:

<h1 class="search-title">
<?php echo $wp_query->found_posts; ?> <?php _e( 'Search Results Found For', 'locale' ); ?>: "<?php the_search_query(); ?>"

This will display the title with the count of the posts found followed by the term that was searched. So it would look something like “15 Search Results Found For: My Search Query”.

If you are looking for a simpler method to add a Wordpress search page, then follow the steps below.

Add WordPress search page using ExpertRec site search

Here we will visit the steps required to add the ExpertRec Custom search engine to your website. This is one of the easiest setup processes of all the available options out there and is highly recommended.

  1. Navigate to https://cse.expertrec.com/newuser?platform=cse and signup with your Google ID.
  2. Enter your website’s URL when prompted. You can select a server location near you and add the URL of your sitemap if you wish to. These will be auto-detected otherwise.
  3. You can play around with the settings and customize the UI as the crawl runs. Once it is complete, you can check out a fully functional demo before taking the search to your website.
  4. You can take the search to your website with little to no effort. All you need to do is to paste the code snippet available on the dashboard on your website.

ExpertRec comes with more customization options that you can explore. You can read this article to find a more detailed guide on the installation and configuration.

By adding this to your website you not only get a fully customizable Wordpress search page, but also a search result page out of the box without any additional configuration required. If you wish to make any changes, it can be done via the ExpertRec control panel without any coding.

Add a Wordpress search page

Are you showing the right products, to the right shoppers, at the right time? Contact us to know more.
You may also like