WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 have added an admin page in wordpress but i needed it to be hidden.I added the page successfully like this

function add_admin_page()
$themename = 'Cesaro';
$page_function = 'admin_page';
add_menu_page($themename." Options", $themename, 'edit_themes', $page_function, 'admin_page');
add_action('admin_menu', 'add_admin_page');

To hide it,i looked at its css using firebug and discovered a pattern or so it seems.Pages added in the format i demonstrated have a css id that starts with #toplevel_page_{page_added} so the css id to the page i added is #toplevel_page_admin_page.

I went ahead and did

display:none !important;

Is this format #toplevel_page_{page added} consistent with all wordpress installations?.

share|improve this question
Why do you want to hide it? There are ways to enable such pages for some selected users only, wouldn’t that be better? – toscho Jul 26 '12 at 11:31
Oh yeah,that's clever so i plan to do this if ( !is_user_logged_in() || !current_user_can('edit_posts') ) wp_die(__("You are not allowed to be here"));. – Gandalf Jul 26 '12 at 14:17
I made some correction to the question.The title should have been how to hide the added admin page menu and not the entire page. – Gandalf Jul 26 '12 at 14:26
up vote 0 down vote accepted

WordPress already takes care of that for you. The third argument in your add_menu_page function, which reads edit_themes is the capability required to access the page. If the user doesn't have that capability he can't access the page, so WordPress won't show him that option on the menu. Clever, no?

Now, from the code you mention on your comments, you're restricting the page to user who can edit_posts. If that's what you want, just use that on the add_menu_page function instead. Otherwise, it doesn't make sense.

PS: If you're planning to add a theme options page, I'd suggest using the add_theme_page function instead, which will nest it within the Appearance section of the menu.

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.