do_action( ‘admin_print_scripts’ )

Fires when scripts are printed for all admin pages.

More Information

  • admin_print_scripts mainly used to echo inline javascript in admin pages header.
  • admin_print_scripts should not be used to enqueue styles or scripts on the admin pages. Use admin_enqueue_scripts instead.
  • admin_print_scripts could be used to insert inline script in admin pages header while admin_print_footer_scripts could be used to insert inline script in admin pages footer.

Source

do_action( 'admin_print_scripts' );

Changelog

VersionDescription
2.1.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    Migrate from Codex:

    Basic Examples:

    function admin_inline_js(){ 
       echo "<script type='text/javascript'>\n";
       echo 'var pluginUrl = ' . wp_json_encode( WP_PLUGIN_URL . '/my_plugin/' ) . ';'; 
       echo "\n</script>"; 
    } 
    add_action( 'admin_print_scripts', 'admin_inline_js' );

    Result:
    <script type=’text/javascript’>
    var pluginUrl = “http://website.com/wp-content/plugins/my_plugin/”;
    </script>

    Note that we use wp_json_encode() to prepare the value for pluginURL before embedding it in the JavaScript code. It is important to always use wp_json_encode() when passing values from PHP to JavaScript, to avoid the possibility of XSS security vulnerabilities.

You must log in before being able to contribute a note or feedback.