Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save petenelson/3209641 to your computer and use it in GitHub Desktop.
Save petenelson/3209641 to your computer and use it in GitHub Desktop.
WordPress: Remove unwanted menu items from the Menu Bar and Toolbar
<?php
/* Remove unwanted menus in WordPress e.g. Posts, Comments and Links */
/* Inspired by http://wordpress.org/extend/plugins/white-label-cms/ */
function ctm_remove_admin_menus() {
global $menu, $submenu;
$exclude[0] = '';
array_push($exclude,__('Posts','default'));
array_push($exclude,__('Comments','default'));
array_push($exclude,__('Links','default'));
unset($exclude[0]);
if (sizeof($exclude) > 0):
if( isset($menu) && is_array($menu) ):
foreach($menu as $mId=>$menuArray):
$tmp = explode(' ',$menuArray[0]);
if(in_array( $tmp[0] , $exclude )):
unset($menu[$mId]);
endif;
endforeach;
endif;
endif;
}
add_action('admin_init', 'ctm_remove_admin_menus');
/* Remove Add Link, Add Post and Comments from the WordPress toolbar */
function ctm_admin_bar(){
global $wp_admin_bar;
$wp_admin_bar->remove_menu('new-post');
$wp_admin_bar->remove_menu('new-link');
$wp_admin_bar->remove_menu('comments');
}
add_action('wp_before_admin_bar_render', 'ctm_admin_bar', 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment