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.

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() )
{
   switch($post->post_name)
    {
        case 'post-name-here':
        wp_register_script( 'charts', "http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js", array('jquery'));
        wp_enqueue_script('charts');
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

1 Answer 1

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

 
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.