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

If I understand is_single() correctly, it's only supposed to return true when the current "post" (in a generic sense) is a literal post (i.e., it has a post_type of post), and that it will return false when the current "post" is a page, attachment, etc. This is what the Codex says:

is_single() returns true if any single post is being displayed
is_singular() returns true when any page, attachment, or single post is being displayed.

But when I try to link a CSS file only into a post, it's still included in attachment pages like http://example.com/?attachment=123456789. Here's the code I'm using:

<?php if ( is_single() ) { ?>
    <link rel="stylesheet" href="style.css" />
<?php } ?>
share|improve this question

The Codex page for is_single should be updated, what you're seeing is correct behavior. According to the main Conditional Tags Codex page:


When any single Post (or attachment, or custom Post Type) page is being displayed. (False for Pages)

You can exclude attachments by also checking ! is_attachment().

Also, you may want to move that code into an enqueue style instead.


if ( is_single() && ! is_attachment() ) :
    echo 'is a single post and not an attachment';
share|improve this answer
daamn that sucks! So there's no way to exclude attachments and get css only on posts page? Thanks – user20428 Sep 14 '12 at 22:32
@user20428 - there is, use is_attachment, see my edit. – Milo Sep 14 '12 at 22:57
You could also use is_singular('post') – Pippin Sep 14 '12 at 23:07
fantastic! that works amazingly thank you very much for your time and the help @milo!!! – user20428 Sep 14 '12 at 23:26
@Pippin that also works great! thank you – user20428 Sep 14 '12 at 23:31

To specifically target single items of a particular post type use is_singular():

if( is_singular( 'post' ) ) {
    // Only execute this block on a single page for a post with type 'post'
share|improve this answer
thank you for the response! – user20428 Sep 14 '12 at 23:33

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.