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 a custom plugin for Wordpress but how in the world do I edit the page header? I need to add some javascript and related codes there.

share|improve this question
    
you want the plugin to add javascript to header of site pages or the admin page? –  amit Aug 3 '12 at 19:01
    
Yes that is correct. How is this possible? –  Peter Aug 3 '12 at 19:04
    
To add javascript code to the header of the admin page. So the plugin settings page in the wp-admin. –  Peter Aug 3 '12 at 19:04
add comment

1 Answer

NOTE

This code will load those scripts on all admin pages. Better you go through the Codex examples to get an idea how you can load the scripts on pages of specific plugins

Here's the code to load the custom scripts on admin pages

function wpse60745_loadto_admin() {

    // to load styles
    wp_register_style( 'my_plugin_css', plugins_url('plugin-style.css', __FILE__) );
    wp_enqueue_style( 'my_plugin_css' );

    //to load javascripts
    wp_register_script( 'my_plugin_js', plugins_url('plugin.js', __FILE__) );
    wp_enqueue_script( 'my_plugin_js' );
}
add_action('admin_enqueue_scripts', 'wpse60745_loadto_admin');

Above code is updated

Reference

share|improve this answer
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.