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

I'm using the below code in my functions.php file to include some JS only in posts I want. The code works fine for published posts and I can target a specific post, but how do I do it for posts that are not yet published, like viewing a draft post?

global $post;

if( is_page() || is_single() )
        case 'post-name-here':
        wp_register_script( 'charts', "http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js", array('jquery'));
share|improve this question
What precisely do you mean by not yet published? Previewing draft post? – Rarst Oct 15 '13 at 19:24
Yes, sorry. That's what I mean! – Scott Helme Oct 15 '13 at 19:26
@Rarst edited for clarity. – Scott Helme Oct 15 '13 at 19:27
up vote 2 down vote accepted

is_preview() is supported. You may also want to look into is_singular() which covers posts, pages, and attachments.

share|improve this answer

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.