Skip to main content Skip to footer
416-479-0685Get a Quote
  • Home
  • About Us
  • Our Work
  • Our Services
  • Get a Quote
  • Blog
  • Contact Us

Blog

03/10/2016

How to customize WordPress search results page

Hello!

When designing websites, especially websites that have an active blog, it is often necessary to style, customize and design the WordPress search results page. When styling the search results, we typically like to modify the way the results are presented as well as append a few custom CSS container classes in order to ensure the results resemble the way content is arranged throughout the rest of the site.

In addition to the CSS containers, we would also manipulate the results containers with responsive CSS @media queries in order to ensure that the results are displayed efficiently and responsively on mobile and tablet devices.

Typically we like to keep things clean and minimal, so the data presented and styling are styled as such. Typically in most WordPress starter themes such as underscores, you will have a standard search.php file which will be our starting point.

Modify your theme’s search.php file

What we want to do is first take a look at the current search results page. If your theme is not presenting a search bar to make an actual search query, then you can simply append the following to your site’s URL : yoursite.com/?s=your+search+string.

Passing this query will send you to the search results page. Ideally your query should actually produce results so you could try to use a general search phrase that you know will produce multiple results.

Once you have a good idea as to how the results looks now, you can visualize a clear direction as far as how you want it to look. The search.php file usually starts with the following code :



    

What we want to do is add a CSS container right above the section with the CSS id “primary”. This will allow us to manipulate all the results :


    

Dont forget to close the div tag at the bottom :

Now that we have a main container wrapping the search results, we can delve deeper into customizing the results as well as the data that is displayed in the actual results.

What I’ll do is move further down in the search.php file and itemize all of the changes. If you wanted to have the search bar displayed on the top of the actual search results pages, you could call the function get_search_form() in this file to display the form. You could then wrap the function in a container with a custom class that we can style later :

The main bulk of the search.php customization will be in the while-loop that queries the posts based on the search phrase. What I’ve done (and will show below) is wrap all the elements of the results such as the title, excerpt and post link URL in custom span CSS classes that I will use to style later.


            
            
            
            
            

You can see three CSS classes defined in the above snippet : search-post-title, search-post-excerpt and search-post-link.

The only other thing I would want to highlight as far as changing and improving the search.php file in your WordPress theme is to reduce the amount of useless information, widgets or sidebars that will be displayed.

A clean page looks much nicer, so we’ll want to comment out the following functions to reduce the amount of clutter that will be displayed on this page :



        

            

        

        

You can see above that I’ve commented out the_posts_navigation(), get_template_part() and get_sidebar(). Depending on how you’ve configured your theme, these functions will produce different results. Removing them outright will produce a very minimal page.

Here’s the search.php file in its entirety :


    
' . get_search_query() . '' ); ?>

Style WordPress search results with CSS

Now comes the fun part, right? What we want to do is modify your theme’s style.css file to add the new classes and ID’s that are necessary to style the search page so it looks good.

The first thing we want to do is declare that search-container class that should be wrapping everything :

.search-container {
    width: 60%;
    padding-left:100px;
    padding-right:100px;
    padding-bottom:200px;
    padding-top:80px;
    margin:auto;
}

Before you get too concerned, we’ll be re-declaring the above container in a @media query to accommodate smaller devices. Next thing we’ll do is add the CSS to style the search form. We want a clean and minimal search form :

#ss-search-page-form {
    text-align:center;
    margin: auto;
    padding-top:50px;
}
#ss-search-page-form .search-field {
    border: 2px solid #dddddd;
    border-radius: 4px;
    width:60%;
    margin-top:20px;
}
#ss-search-page-form .search-submit {
    padding: 10px 10px;
    margin-bottom:5px;
    text-transform: uppercase;
}

You can see we are using the ID ss-search-page-form to apply the styling. Next we get to the CSS styling of the actual search results themselves :

.search-page-title {
    font-family: 'Open Sans', sans-serif;
    font-size: 34px;
    font-weight: 300 !important;
    letter-spacing: 2px;
    line-height: 50px;
    text-align:center;
    display:block;
    text-transform:uppercase;
    padding-top:50px;
    padding-bottom:25px;
}
.search-post-title {
    font-family: 'Open Sans', sans-serif;
    font-size: 18px;
    font-weight: 600 !important;
    letter-spacing: 2px;
    line-height: 50px;
    text-align:left;
    display:block;
}
.search-post-link {
    font-family: 'Open Sans', sans-serif;
    font-size: 14px;
    font-weight: 300 !important;
    letter-spacing: 2px;
    line-height: 20px;
    text-align:left;
    display:block;
}
.search-post-excerpt {
    font-family: 'Open Sans', sans-serif;
    font-size: 12px;
    font-weight: 400 !important;
    letter-spacing: 2px;
    line-height: 15px;
    text-align:left;
    display:block;
}

You can see that we’re applying the font family “Open Sans”. Obviously you can make your own customization to apply a different font or simply inherit the fonts already applied elsewhere.

Set responsive media queries for WordPress search results

This is obviously an important part of the process. You want to make sure that the results are not “squished” and that the content responds to the screen’s width so that it can still be easily read no matter what device you are on.

@media only screen and (max-width: 768px) {
        .search-container {
        width: 100%;
        padding-left:15px;
        padding-right:15px;
    }
}

We are using a media query with a popular “max-width” breakpoint of 768 pixels. If you already have breakpoints defined, you could inject the CSS class declarations in that. Otherwise, the above CSS simply reduces the left/right padding and extends the percentage width of the container itself to 100%. Simple enough?

After customizing the search results with the above considerations, you might get a search results page similar to the screenshot below. I hope this helps you with your WordPress web design project!

wordpress-search-results

FAQs

  • How do I access the search results page in WordPress?

    Viewing search results directly

    To access the search results page in WordPress, append your search query to your site’s URL in the format: yoursite.com/?s=your+search+string. This will display the search results for the specified query.

  • What is the purpose of modifying the search.php file?

    Customizing search results display

    Modifying the search.php file allows you to customize how search results are displayed on your WordPress site. You can add CSS classes, adjust the layout, and control which elements are shown to create a cleaner and more user-friendly search results page.

  • How can I style the search results page with CSS?

    Applying custom styles

    You can style the search results page by adding CSS rules to your theme’s style.css file. Define styles for the custom classes you added in the search.php file, such as .search-container and .search-post-title, to achieve the desired look and feel.

  • What are media queries and why are they important?

    Ensuring responsive design

    Media queries are a CSS technique used to apply styles based on the device’s screen size. They are important for ensuring that your search results page is responsive, allowing it to display correctly on different devices, such as desktops, tablets, and smartphones.

  • How can I reduce clutter on the search results page?

    Simplifying the layout

    To reduce clutter on the search results page, you can comment out or remove unnecessary functions in the search.php file, such as navigation links and sidebars. This will create a cleaner layout, focusing solely on the search results.

Shift8 is an award-winning Toronto website design and development team with nearly 20 years experience.

We plan, design, and build custom WordPress sites for startups through enterprise, pairing UX and branding with clean code, performance, and security.

Our milestone-driven process keeps communication clear and timelines on track—fast prototypes, focused feedback, then smooth launch and support.

From accessibility and SEO to hosting, hardening, and ongoing care, we handle the details so you can scale.

If you’re looking for web design Toronto businesses trust, our website design work is built to ship, convert, and last.

Need Web Design?

Fill out the form to get a free consultation.


Shift8 Web Toronto – 416-479-0685
203A-116 Geary Ave. Toronto, On M6H 4H1, Canada
© 2024. All Rights Reserved By Star Dot Hosting Inc.

Web Design | Web Development

Contact Us
Phone: 416-479-0685
Toll Free: 1-866-932-9083 (Press 1)
Email: Sales@Shift8web.Com
Atomic Edge WAF