1

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?

1 Answer 1

2

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

2
  • 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 Commented Sep 25, 2013 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. Commented Sep 25, 2013 at 2:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.