WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


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


share|improve this answer

Your Answer


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.