I have a search results page with a template call content-search.php.

Basically what this file does is to display the results after a person searches something on the search bar, and i would like to edit the css of this file.

So what I attempted was , i went to functions.php and added the usual code like this


function content_search_styles() {
    if ( is_page_template( 'content-search.php' ) ) {
        wp_enqueue_style( 'page-template', get_stylesheet_directory_uri(). '/css/content-search.css' );
add_action( 'wp_enqueue_scripts', 'content_search_styles' );


<article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?>>
    <h2>Search Results</h2>
    <b>Results as following</b>
    <?php the_title('<h1 class="entry-title">','</h1>' ); ?>

    <?php if( has_post_thumbnail() ): ?>
        <div class="pull-left"><?php the_post_thumbnail('thumbnail'); ?></div>
    <?php endif; ?>

    <small><?php the_category(' '); ?> || <?php the_tags(); ?> || <?php edit_post_link(); ?></small>

    <?php the_excerpt(); ?>




body {
    display:none !important;

The CSS does not reflect on the search results page,

Please advise and thank you very much once again

  • Is the content-search.php file placed directly in the root of the theme? if not you need to specify the relative path to the root of the theme Commented Feb 12, 2019 at 16:39

1 Answer 1


I bet that you’re misunderstood what is_page_template is really doing. From Codex:

This template tag allows you to determine if you are in a page template. You can optionally provide a template name or array of template names and then the check will be specific to that template.

And if you’ll take a look at it’s code:

function is_page_template( $template = '' ) {
    if ( ! is_singular() ) {
        return false;
    $page_template = get_page_template_slug( get_queried_object_id() );

... you’ll get, that you can’t use this function to target search results. It won’t work, because it’s meant to check if current page uses given page template. On the other hand you want to check if given file is currently used...

If your theme is coded correctly, then you should use is_search() instead.

  • Hey there, thank you very much good Sir, this has solved my issue, once again, i really appreciate that you took the effort to clarify to me and solved my issue, once again, thank you very much
    – desh
    Commented Feb 12, 2019 at 23:57
  • Yup already marked it correct, already upvoted it but since i have less than 15 reputation points it won't be reflected. Anyways thank you very much for your help and you have been such a good help for me :)
    – desh
    Commented Feb 13, 2019 at 5:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.