wordpress is_page() problem

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)){….

Read More

But nothing happens. It’s not included and noe ‘yeeesssss’ is displayed.
Any idea?

Cheers, Joerg

Related posts

Leave a Reply

2 comments

  1. 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:

    function myplugin_css() {
        if ( is_page( 'myinfopage' ) ) {
            wp_enqueue_script( 'RGraph' );
        }
    }
    add_action( 'wp_print_scripts', 'myplugin_css' );