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 am writing my first plugin and I have this code in the main plugin php to replace home page with custom template

add_filter( 'template_include', 'replace_home_page' );

function replace_home_page( $template ) {
      if (is_home()){
    return plugin_dir_path( __FILE__ ) . 'mhomepagetemplate.php';
  }
  return $template;
}

before above code I call code to register some javascript

    $main_js_name='mhp_main.js';

    function load_js(){
        wp_enqueue_script($main_js_name,plugins_url($plugin_name.'/js/'.$main_js_name),array( 'jquery' ));
echo    '<BR><BR>'. plugins_url($plugin_name.'/js/'.$main_js_name);
    }

    add_action('wp_print_script','load_js');

the javascript file contains only one line now

console.log('test from js');

I was expecting to see the text text from js in javascript console but it is not there. I cannot find the code anywhere on the home page.

The custom template calls <?php wp_head(); ?>

Could someone help me to make the javascript work?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

The action is plural: wp_print_scripts, however, the action you want to enqueue scripts on is wp_enqueue_scripts.

share|improve this answer
    
I don't understand what you want to say. Could you be specific what I need to do? The Codex says that it's wp_enqueue_script codex.wordpress.org/Function_Reference/wp_enqueue_script –  Radek Sep 25 '13 at 2:49
    
Did you follow the link and read the page? The function wp_enqueue_script should be used on the action wp_enqueue_scripts. –  Milo Sep 25 '13 at 2:53
    
It's working now. Thank you for your time. –  Radek Sep 25 '13 at 3:19
add comment

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.