Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

2 Answers

up vote 8 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.

http://codex.wordpress.org/Function_Reference/is_singular

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
add comment

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() ) {
  // DO STUFF
}

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

if ( is_single() && 'post' == get_post_type() ) {
  // DO STUFF
}
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
add comment

Your Answer

 
discard

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.