Adding scripts to admin page in my theme

Use add_action('admin_enqueue_scripts', 'pb_admin_style'); and as the manual states, the admin_enqueue_scripts can also be used to target a specific admin page. Use this to only select the admin page you want.

function pb_admin_style($hook) {
    if( 'edit.php' != $hook )
        return;
    wp_enqueue_script( 'my_custom_script', plugins_url('/myscript.js', __FILE__) );
}
add_action( 'admin_enqueue_scripts', 'pb_admin_style' );

Leave a Comment