How to remove menu and submenu items in WordPress backend - wordpress

I need to hide / remove a menu and submenu in WordPress backend.
Main menu item:
admin.php?page=themeit_dashboard
Sub menu items:
admin.php?page=themeit_dashboard&tab=builder
admin.php?page=_options&tab=1
admin.php?page=themeit_dashboard&tab=license
I have tried the code below code, but that does not work. Two of the subpages link to the same page but show different tabs.
function remove_menus(){
if ( !current_user_can( 'manage_options' ) ) {
remove_menu_page( 'admin.php?page=themeit_dashboard' ); //themeit
remove_submenu_page( 'admin.php?page=themeit_dashboard', 'admin.php?page=themeit_dashboard&tab=builder' ); //themeit
remove_submenu_page( 'admin.php?page=_options', 'admin.php?page=_options&tab=1' ); //themeit
remove_submenu_page( 'admin.php?page=themeit_dashboard', 'admin.php?page=themeit_dashboard&tab=license' ); //themeit
}
}
add_action( 'admin_menu', 'remove_menus' );

You can do it by using current_user_can() and remove_menu_page, as you tried to do.
But It can be done by without coding too.... long back I was using a plugin called - "Advanced Access Manager". Use that or any similar plugins.
With those you will be able to assign permisson on menus based on roles with a cool UI.
I personally did found it very easy.

Related

How to remove the only the Themes options from the Apprerance menu

I want to only remove the Themes option from the Appearance menu in the WordPress dashboard. The option I want removed is marked in red.
I have tried,
remove_menu_page( 'themes.php' );
But it removed the Appearance menu completely.
I found another function to remove the sub menu but unsure what the second option has to be since both Appearance and Themes are linked to wp-admin/themes.php
remove_submenu_page( 'themes.php', '')
This will do it. Add to functions file:
function remove_menus(){
remove_submenu_page( 'themes.php', 'themes.php');
}
add_action( 'admin_menu', 'remove_menus' );

Wordpress menus shows changed items only to logged in user

I'm working on a wordpress website where i have a problem. I need to change the main menu and remove some entries, theese entries are removed only for logged in users, if i go to the website as anonymous user i see the original menu with all elements. I'm going crazy.
use this https://wordpress.org/plugins/if-menu/,
or you can use "is_admin" in four functions.php too.
For that, you will need to remove those items from your menu and then please place the following code in your functions.php file, and replace the items and links
function add_login_logout_register_menu( $items, $args ) {
if ( $args->theme_location != 'primary' ) {
return $items;
}
if ( is_user_logged_in() ) {
$items .= '<li class="right">'. __("item1") .'</li>';
$items .= '<li class="right">'. __("item1") .'</li>';
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'add_login_logout_register_menu', 199, 2 );
i already installed "IF MENU" plugin, but it didn't work for my website, so i removed id. after that, i cannot update the "anonymous" menu anymore (it seems to happen mainly in the home page). It seems that IF MENU broken my website

Completely customize admin menu without plugin

Basically what I want is to remove most of the admin menu and replace it with my own, without using a plugin. But I'd also like it to stay after a wp update.
Is this a possibility and if so, how?
Or is it just a million times easier to make the plugin and be done with it?
EDIT
In /wp-admin there is a menu on the left side. I won't be needing most of the menu and therefor don't want others to see or edit stuff in there(because the only thing that will happen is it will break the site). So I want to remove the unnecesary menu items and add relevant menu items. (It's about Posts, Pages, Media etc)
As others already mentioned you could use the function remove_menu_page, but you still have to put this code somewhere.
If you really don't want to create a plugin you could add this code to the functions.php file of your theme.
In my opinion it's not theme related code, so it would be better to put it in a custom plugin. And it's really easy, here's a video on how to create one within minutes:
https://www.youtube.com/watch?v=S9Nhb1KX7vM
In your case it would look something like:
<?php
/*
Plugin Name: Custom Admin Menu
Version: 1.0.0
Description: My Custom Admin Menu
Author: Peter van der Net
*/
if (!function_exists('my_custom_admin_menu')):
function my_custom_admin_menu(){
remove_menu_page('index.php');
remove_menu_page('plugins.php');
remove_menu_page('users.php');
// etcetera..
}
add_action('admin_menu', 'my_custom_admin_menu');
endif;
/*?>*/
Put this code in a file named custom-admin-menu.php in the folder wp-content/plugins. And then activate the plugin.
although it is not necessary and there are a lot of other ways to secure your wordPress install but still you can refer the below page and this will answer your question
https://codex.wordpress.org/Function_Reference/remove_menu_page
Hope this helps
Take care and Happy coding
This function should be called on the admin_menu action hook.
<?php
function custom_menu_page_removing() {
remove_menu_page( $menu_slug );
}
add_action( 'admin_menu', 'custom_menu_page_removing' );
?>
Removes every menu for all users.
<?php
function remove_menus(){
remove_menu_page( 'index.php' ); //Dashboard
remove_menu_page( 'jetpack' ); //Jetpack*
remove_menu_page( 'edit.php' ); //Posts
remove_menu_page( 'upload.php' ); //Media
remove_menu_page( 'edit.php?post_type=page' ); //Pages
remove_menu_page( 'edit-comments.php' ); //Comments
remove_menu_page( 'themes.php' ); //Appearance
remove_menu_page( 'plugins.php' ); //Plugins
remove_menu_page( 'users.php' ); //Users
remove_menu_page( 'tools.php' ); //Tools
remove_menu_page( 'options-general.php' ); //Settings
}
add_action( 'admin_menu', 'remove_menus' );
?>
For detailed explanation: URL

how to hide activated menu link from wp-admin dashboard [duplicate]

Is it possible to get activate plugin list in wordpress and remove it from admin menu bar ?. i want to remove all activate plugin links from adminu bar .
Findout the page and replace your_plugin_page .
<?php
function remove_menus(){
remove_menu_page( 'your_plugin_page.php' ); //probably where the plugin settings are available
}
add_action( 'admin_menu', 'remove_menus' );
?>
This will list out all activated plugins:-
$apl=get_option('active_plugins');
$plugins=get_plugins();
$activated_plugins=array();
foreach ($apl as $p){
if(isset($plugins[$p])){
array_push($activated_plugins, $plugins[$p]);
}
}
now you need to get all the pages .Not a perfect solution , but I hope it will be helpful.

Remove "Updates" link from Wordpress Admin Dashboard

Does anyone knows how to remove the menu link named "Updates", found under the "Dashboard" section of the Wordpress Administration Menu?
I added the following actions & filters, which stop the core, theme & plugins updates, but the menu link is still there, although there is nothing to update:
# Disable WP>3.0 core updates
add_filter( 'pre_site_transient_update_core', create_function( '$a', "return null;" ) );
# Disable WP>3.0 plugin updates
remove_action( 'load-update-core.php', 'wp_update_plugins' );
add_filter( 'pre_site_transient_update_plugins', create_function( '$a', "return null;" ) );
# Disable WP>3.0 theme updates
remove_action( 'load-update-core.php', 'wp_update_themes' );
add_filter( 'pre_site_transient_update_themes', create_function( '$a', "return null;" ) );
# disable edit plugin and theme files:
define('DISALLOW_FILE_EDIT',true);
# disable core updates:
add_filter( 'pre_site_transient_update_core', create_function( '$a', "return null;" ) );
Thank you,
Ciprian
#wunderdojo wasn't "wrong", but WordPress has a bit of a better built in mechanism to handle this.
What you want (or anyone else viewing this these days) is a function called remove_submenu_page
Codex link: https://codex.wordpress.org/Function_Reference/remove_submenu_page
add_action( 'admin_menu', 'control_menu_items_shown' );
function control_menu_items_shown() {
remove_submenu_page( 'index.php', 'update-core.php' );
}
index.php is the name for the "Dashboard" menu item and update-core.php is the name for the "Updates" menu sub item.
Please note the naming mechanisms of these change quite a bit depending on the plugin, theme, etc.
Example from the Mandrill plugin:
remove_submenu_page( 'options-general.php', 'wpmandrill' );
They may not end in .php
It's also worth noting a similiar function remove_menu_page
Codex link: https://codex.wordpress.org/Function_Reference/remove_menu_page
Hope someone finds this useful in the future.
The update options comes in two places in back-end. One as the message on top and second in the 'AT a glance' window in dashboard. Place the below code in your functions.php. This code will hide the update options from these two areas.
add_action('admin_menu','wphidenag');
function wphidenag() {
remove_action( 'admin_notices', 'update_nag', 3 );
}
function admin_style() { ?>
<style>
#wp-version-message a.button{
display:none;
}
</style>
<?php
}
add_action('admin_enqueue_scripts', 'admin_style');
This should do it:
function edit_admin_menus() {
global $submenu;
unset($submenu['index.php'][10]);
return $submenu;
}
add_action( 'admin_menu', 'edit_admin_menus' );
Put that in your theme's functions.php file or in your plugin code.

Resources