I'm building a site which needs to have two search bars and two search results templates. One of the search bars is for regular posts, and the other is for a custom post type.

I need the two search results pages to be styled completely differently, so I have set up two templates to display results. One is the standard search.php that detects if the post type is a custom one, and displays it on a template named new-index.php

Im trying to attach different style sheets to the different pages using the following code:

if ( is_page_template('new-index.php')) { ?>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/home.css" />
<?php } ?>

which dosen't work, but if i use:

if ( is_search()) { ?>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/gallery.css" />
<?php } ?>

it works fine but it gives both the templates the same style sheet, I understand why its happening, but cannot figure out a way around it, any suggestions?

1 Answer 1


I've never used is_page_template() but I have had good luck with is_page('new_search') regardless of which conditional you use some things to check.

Is the is_page_template('new-index.php') working. you may test this by doing something like:

if ( is_page_template('new-index.php')) { wp_die('new search page');}

You should also use wp_register_style and wp_enqueue_style in your functions.php hooking in the the wp_head which you should have better luck with.

  • is_page won't target it and the wp_die test didn't work! I haven't used wp_register_style before, I usually am able to link style sheets to different pages this way. is_search() is still the only one that affects it!
    – RoseCoder
    Jun 27, 2013 at 15:13
  • If the wp_die() didn't work then something is either wrong with the template name or how you are registering/displaying the custom search page. Could you provide more code or a link? Also your method works but wp_register_style is the more standard (WordPress) way to do it.
    – Brooke.
    Jun 27, 2013 at 21:21

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.