WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I'm using is_single(); in my <head> section to add some style to website navigation it executes correctly on blog posts but it also executes on single "portfolio" post type posts (so single-portfolio.php and single.php).

How do I make it execute only on single.php?

share|improve this question
up vote 12 down vote accepted

You can use the following instead,

if (is_singular('post')) {

    //your code here...


Where by is_singular is the WordPress API conditional function for testing for the existence of a post type. You can also pass an array of post types if you wish.


share|improve this answer
That's another very good answer! Both answers resolve this issue. This one seems to be simpler. Thanks! – Paul Jul 28 '12 at 15:19
Thank you, always best to use built-in functions. I think this should be the accepted answer. – Simon Jul 28 '12 at 15:19

You could try something like (http://codex.wordpress.org/Function_Reference/get_post_type) :

to check if it's not a specific post-type :

if ( is_single() && 'portfolio' != get_post_type() ) {

or to check if it's a post and not a post-type :

if ( is_single() && 'post' == get_post_type() ) {
share|improve this answer
Thanks! That resolves my problem BUT what if I have "slideshow", "news", "portfolio" and a lot more post types? Some can be extended using plugins and I'm not sure how many there will be and what will be their names. Is there a way to do it without excluding just "portfolio" but everything that is not a blog post? – Paul Jul 28 '12 at 15:15
@Flow: use get_post_type() to check for 'post'. – Geert Jul 28 '12 at 15:17
I have updated my answer ^^ – Simon Jul 28 '12 at 15:18
Thanks so much! The issue is resolved :) – Paul Jul 28 '12 at 15:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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