How to get the post_name when in preview?

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');

Related posts

1 comment

Comments are closed.