I am building a plugin and I would like to be able to hide the wordpress admin side menu and top bar when a specific page is shown(or menu item clicked)?

Should I call the jquery directly as a script on the plugin page's code, or is there a way I can execute the jquery when the page is loading, or menu item is clicked from a hooked function with ajax or something similar? Here is the jquery I wan't to run:

$("#wpadminbar, #adminmenuwrap").hide();
  • How are you enqueueing your Plugin's script(s)? Please post all relevant code, in context. – Chip Bennett Jan 13 '14 at 20:59
  • If all you're using is .hide() then maybe it makes sense to just do it via CSS. – Chief Alchemist Jan 14 '14 at 1:45

You'll need to get the screen id on the screen (or page) in question using get_current_screen()


Then, hook into it with the following:

function my_script_function() {
    if ( strpos( get_current_screen()->id, 'screen_id' ) !== false ) {
        wp_enqueue_script( 'my_javascript_handle', 'path/to/my/script.js', 'jquery', '1.0' );
add_action( 'admin_enqueue_scripts', 'my_script_function' );

This will enqueue your script properly in the WordPress system along with jQuery core (just in case it isn't already there).

http://digwp.com/2009/06/including-jquery-in-wordpress-the-right-way/ has a good overview of using jQuery in WordPress. Please note that by default though you can't use $ to call jQuery as it is in safe mode (the article will show you how to change it from having to use jQuery.

  • Thank you Chris, this works exactly as needed. I appreciate it. – user1632018 Jan 15 '14 at 23:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.