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 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();
share|improve this question
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
up vote 1 down vote accepted

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.

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

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.