I want to load a .js file only on a specific page in WordPress 3.1.2
So I use in functions.php
function my_init_method() {
if (is_page('myinfopage')){
echo "yeeessssssss";
//wp_register_script('RGraph',get_stylesheet_directory_uri() . '/js/RGraph/RGraph.common.core.js' );
}
}
add_action('init', 'my_init_method');
The page is 100% ‘myinfopage’. I tried it also with the pageID 24
if (is_page(24)){….
But nothing happens. It’s not included and noe ‘yeeesssss’ is displayed.
Any idea?
Cheers, Joerg
You probably want to drop the conditional during init. You are just registering the script here, not enqueueing it. Once registered, you should be able to call the script later in the action sequence. Please try something like this:
add_action just hooks a function call to an event. In order to originally call the action you should use do_action..
Refer http://codex.wordpress.org/Function_Reference/do_action