I have this code to enqueue a script file when the page is not single.php (neither admin page):
//functions.php
/********************** Add JS file **************************/
function my_own_scripts() {
if (! is_admin() && ! is_single()) {
wp_register_script( 'my_javascript_file',get_bloginfo('stylesheet_directory') . '/js/my_javascript_file.js', array( 'jquery' ) );
wp_enqueue_script( 'my_javascript_file' );
}
}
add_action( 'wp_enqueue_scripts', 'my_own_scripts' );
But the script is always enqueued. Also in a single post entry.
I've read this post, but doesn't help me. Of course, the theme is using single.php and is_single() works with other functions.
Any idea?
Edit:
I've found out that is_single() is always returning false, even when single.php is loaded. I can't see why this function is not working as expected while it is working right inside all other functions inside functions.php.
get_bloginfo('stylesheet_directory'). You should be usingget_stylesheet_directory_uri().