I'm using a WooThemes child theme and want to hide the menu from the WordPress admin bar. I use the following code so that only the users held within the array get to see all the options.
function remove_items_from_menu() {
$admins = array(
'Bill', 'Steve', 'Rob'
);
$current_user = wp_get_current_user();
if( !in_array( $current_user->user_login, $admins ) ) {
// exit;
add_filter('acf/settings/show_admin', '__return_false');
remove_action('load-update-core.php','wp_update_plugins');
remove_action( 'admin_notices', 'update_nag', 3 );
remove_menu_page('edit.php?post_type=acf-field-group');
remove_menu_page('edit-comments.php');
remove_menu_page('tools.php');
remove_submenu_page( 'index.php', 'update-core.php' );
remove_menu_page('themes.php');
remove_menu_page('plugins.php');
remove_submenu_page( 'themes.php', 'themes.php' );
remove_submenu_page( 'themes.php', 'widgets.php' );
remove_submenu_page( 'themes.php', 'customize.php' );
remove_submenu_page( 'themes.php', 'theme-editor.php' );
remove_submenu_page('options-general.php', 'options-permalink.php');
remove_submenu_page('options-general.php', 'options-media.php');
remove_submenu_page('options-general.php', 'options-discussion.php');
remove_submenu_page('options-general.php', 'options-reading.php');
remove_submenu_page('options-general.php', 'options-writing.php');
remove_submenu_page( 'options-general.php', 'social-sharing-admin' );
}
}
add_action( 'admin_menu', 'remove_items_from_menu', 999 );
?>
Finding the page to hide for the theme displays itself as admin.php?page=woothemes, but adding the following line to the above code still doesn't hide it from view.
remove_menu_page('admin.php?page=woothemes');
Does anybody know how I can find out the correct page ID to hide this specific menu option? I've searched online and cannot find how to hide a WooThemes menu from the admin bar.
Thanks.
It depends on the id passed to add_menu_page when it was called by the WooTheme. You can search over the code, but I think that
remove_menu_page('woothemes');
should do it.
Hope it helps.
Related
I am trying to add a different menu title. Like "Goto" should be "More" but if you click on it it should still go to the first.
add_action('admin_menu', 'my_menu_pages');
function my_menu_pages(){
add_menu_page('More', 'More', 'manage_options', 'my-menu', 'edit.php?post_type=goto' );
add_submenu_page('my-menu', 'Goto', 'Goto', 'manage_options', 'edit.php?post_type=goto' );
add_submenu_page('my-menu', 'Gallerys', 'Gallerys', 'manage_options', 'edit.php?post_type=join' );
}
Add the follows code snippet in your active theme's functions.php to achieve the above -
add_action( 'admin_menu', 'fix_admin_menu', 999 );
function fix_admin_menu(){
global $submenu;
if ( ! isset( $submenu['my-menu'] ) ) {
return;
}
unset( $submenu['my-menu'][0] );
}
I am using a wordpress theme which supports woocommerce,
when adding a user with shop manager role i don't want to show the woocommerce menu.
Just need the products menu only.
please help.
You can use WordPress's 'remove_menus()' function to do this.
Store Managers have a capability: 'manage_woocommerce'
You can see that they are allowed to see the WooCommerce admin menu here:
'/wp-content/plugins/woocommerce/includes/admin/class-wc-admin-menus.php'
Look for: $main_page = add_menu_page( __( 'WooCommerce', 'woocommerce' ), __( 'WooCommerce', 'woocommerce' ), 'manage_woocommerce', 'woocommerce' , array( $this, 'settings_page' ), null, '55.5' );
So much for the theory. To stop this admin menu item from displaying for anyone but an Administrator, add this to your functions.php file or plugin:
add_action( 'admin_menu', 'remove_menus' );
function remove_menus(){
// If the current user is not an admin
if ( !current_user_can('manage_options') ) {
remove_menu_page( 'woocommerce' ); // WooCommerce admin menu slug
}
}
Don't have the rep points to add a comment, but needs to change the hooked action from:
add_action( 'admin_menu', 'remove_menus' );
to:
add_action( 'admin_init', 'remove_menus' );
and then you can do something like:
function remove_menus(){
// If the current user is not an admin
if ( !current_user_can('manage_options') ) {
remove_submenu_page('woocommerce', 'wc-status');
}
}
if you are trying to remove core woocommerce submenu items.
(responding to Do Xuan Nguyen's comment)
I have this code that removes pages from users that are not admin on a site I developing.
function remove_menu_items() {
if (!current_user_can('manage_options')){
remove_menu_page( 'index.php' );
remove_menu_page( 'edit-comments.php' );
remove_menu_page( 'edit.php' );
remove_menu_page( 'edit.php?post_type=page' );
remove_menu_page( 'edit.php?post_type=hp_slides' );
remove_menu_page( 'post-new.php?post_type=foodswaps' );
}
}
add_action( 'admin_menu', 'adjust_the_wp_menu', 999 );
However the bottom remove item doesn't work, the post type is correct but the sub menu item still remains. Can any one see what I have done wrong?
I had this problem a couple weeks ago!
So you are trying to remove a submenu item, therefore need to use something like this:
function remove_menu_items() {
if ( ! current_user_can( 'manage_options' ) ) {
// remove new post button from the food swaps custom post type if not admin
$page = remove_submenu_page( 'edit.php?post_type=foodswaps', 'post-new.php?post_type=foodswaps' );
}
}
add_action( 'admin_menu', 'remove_menu_items' );
How can I remove Header and Background subpages from Appearance submenu?
remove_submenu_page works great with Themes and Menus, but I can't seem to find a way to remove Header and Background!
Here's an example:
// working just fine:
remove_submenu_page( 'themes.php', 'themes.php' );
remove_submenu_page( 'themes.php', 'nav-menus.php' );
// not working:
remove_submenu_page( 'themes.php', 'themes.php?page=custom-header' );
remove_submenu_page( 'themes.php', 'themes.php?page=custom-background' );
Use Following code in your theme's function.php
add_action( 'after_setup_theme','remove_twentyeleven_options', 100 );
function remove_twentyeleven_options() {
remove_custom_background();
remove_custom_image_header();
}
remove_custom_background(); is deprecated as of WordPress 3.4
Use remove_theme_support( 'custom-background' ); instead.
I want to remove a few sub menu items from the admin menu in WordPress. I have found the following which can remove certain sub menu items...
add_action( 'admin_menu', 'adjust_the_wp_menu', 999 );
function adjust_the_wp_menu() {
$page = remove_submenu_page( 'themes.php', 'widgets.php' );
}
...but what if it is not a standard php such as "themes.php?page=custom-header" that I would like removed.
This worked for me. Thanks to Ravi for pointing me in the right direction.
add_action( 'init', 'remove_taxonomy_menu_pages', 999 );
function remove_taxonomy_menu_pages() {
// remove products->categories
register_taxonomy('product_cat',
'woocommerce_taxonomy_objects_product_cat', array('show_ui' => false)
);
// remove products->tags
register_taxonomy('product_tag',
'woocommerce_taxonomy_objects_product_tag', array('show_ui' => false)
);
// remove products->shipping classes
register_taxonomy('product_shipping_class',
'woocommerce_taxonomy_objects_product_shipping_class', array('show_ui' => false)
);
}
add_action( 'admin_menu', 'remove_submenu_pages', 999 );
function remove_submenu_pages() {
// remove products->attributes
remove_submenu_page( 'edit.php?post_type=product', 'woocommerce_attributes');
}
Add code in your function.php
Remove "themes.php?page=custom-header" option using this code.
function remove_twentyeleven_options() {
remove_custom_image_header();
}
add_action( 'after_setup_theme','remove_twentyeleven_options', 100 );
I would like to share, that's how you can remove woocommerce submenu's
Product Attributes
Product Shipping Class
--
add_action( 'admin_menu', 'remove_taxonomy_menu_pages', 999 );
function remove_taxonomy_menu_pages() {
remove_submenu_page( 'edit.php?post_type=product', 'product_attributes' );
remove_submenu_page( 'edit.php?post_type=product', 'edit-tags.php?taxonomy=product_shipping_class&post_type=product');
}