admin管理员组文章数量:1022752
I am trying to remove two links from users dashboard keeping it on admin but it goes off on both user and admin.
One i need to remove from user dashboard and other is contact form plugin link contact.
I am trying t o use below code.also post link goes off.
add_filter( 'admin_menu', 'remove_menus', 99 );
if (!current_user_can('manage_options')) {
add_action('wp_dashboard_setup', 'remove_menus' );
}
function remove_menus(){
remove_menu_page( 'index.php' ); //dashboard
}
I am trying to remove two links from users dashboard keeping it on admin but it goes off on both user and admin.
One i need to remove from user dashboard and other is contact form plugin link contact.
I am trying t o use below code.also post link goes off.
add_filter( 'admin_menu', 'remove_menus', 99 );
if (!current_user_can('manage_options')) {
add_action('wp_dashboard_setup', 'remove_menus' );
}
function remove_menus(){
remove_menu_page( 'index.php' ); //dashboard
}
Share
Improve this question
edited Dec 28, 2018 at 15:17
fuxia♦
107k39 gold badges255 silver badges459 bronze badges
asked Dec 28, 2018 at 10:30
FernaFerna
31 silver badge4 bronze badges
4 Answers
Reset to default 0you should follow the below code and also see the wordpress docs
<?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' );
?>
wordpress official docs :-
https://codex.wordpress/Function_Reference/remove_menu_page
page restriction at admin site for particular user redirect when user reached there.
add_action( 'current_screen', 'restrict_screen' );
function restrict_screen() {
if ( is_admin() ) {}
else{
$current_screen = "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$indexpage = 'index.php';
$editpage = 'edit.php';
$match = strpos( $current_screen, $editpage );
$match2 = strpos( $current_screen, $indexpage );
if( $match == TRUE || $match2 == TRUE ) {
// wp_die('get out');
$current_admin = get_admin_url() . 'profile.php';
header('Location: ' . $current_admin . '', true, 301);
}
}
}
You can try this :)
add_filter( 'admin_menu', 'remove_menus', 99 );
function remove_menus(){
if(!current_user_can('administrator'))
remove_menu_page( 'index.php' ); //dashboard
}
Admin menus and plugin menus are two different. You need to use separate actions to hide admin menus and plugin menus from admin dashboard. Here is how.
// Hide Admin Menus
function remove_menus() {
remove_menu_page( 'plugins.php' );
remove_menu_page( 'users.php' );
remove_menu_page( 'options-general.php' );
}
add_action( 'admin_menu', 'remove_menus' );
// Hide plugin menus
function remove_plugin_menu_pages() {
remove_menu_page( 'edit.php?post_type=acf' );
remove_menu_page( 'wpcf7' );
remove_menu_page( 'itsec' );
remove_menu_page( 'cptui_main_menu' );
remove_menu_page( 'revslider' );
}
add_action( 'admin_init', 'remove_plugin_menu_pages' );
Here's what worked for me. This will only show Menu Items to Admin role & hide for other role(s). If you want to hide for Admin also, then remove the if statement.
// Hide Admin Menus from WP-Dashboard
add_filter( 'admin_menu', 'remove_menus');
function remove_menus(){
if(!current_user_can('administrator')) {
remove_menu_page( 'edit.php?post_type=page' ); //Contact Form7
remove_menu_page( 'edit.php?post_type=portfolio_item' ); //CPT
remove_menu_page( 'wpcf7' ); //Contact Form7
remove_menu_page( 'tools.php' ); //Tools
remove_menu_page( 'vc-welcome' ); //WPBakery Page Builder
}
}
I am trying to remove two links from users dashboard keeping it on admin but it goes off on both user and admin.
One i need to remove from user dashboard and other is contact form plugin link contact.
I am trying t o use below code.also post link goes off.
add_filter( 'admin_menu', 'remove_menus', 99 );
if (!current_user_can('manage_options')) {
add_action('wp_dashboard_setup', 'remove_menus' );
}
function remove_menus(){
remove_menu_page( 'index.php' ); //dashboard
}
I am trying to remove two links from users dashboard keeping it on admin but it goes off on both user and admin.
One i need to remove from user dashboard and other is contact form plugin link contact.
I am trying t o use below code.also post link goes off.
add_filter( 'admin_menu', 'remove_menus', 99 );
if (!current_user_can('manage_options')) {
add_action('wp_dashboard_setup', 'remove_menus' );
}
function remove_menus(){
remove_menu_page( 'index.php' ); //dashboard
}
Share
Improve this question
edited Dec 28, 2018 at 15:17
fuxia♦
107k39 gold badges255 silver badges459 bronze badges
asked Dec 28, 2018 at 10:30
FernaFerna
31 silver badge4 bronze badges
4 Answers
Reset to default 0you should follow the below code and also see the wordpress docs
<?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' );
?>
wordpress official docs :-
https://codex.wordpress/Function_Reference/remove_menu_page
page restriction at admin site for particular user redirect when user reached there.
add_action( 'current_screen', 'restrict_screen' );
function restrict_screen() {
if ( is_admin() ) {}
else{
$current_screen = "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$indexpage = 'index.php';
$editpage = 'edit.php';
$match = strpos( $current_screen, $editpage );
$match2 = strpos( $current_screen, $indexpage );
if( $match == TRUE || $match2 == TRUE ) {
// wp_die('get out');
$current_admin = get_admin_url() . 'profile.php';
header('Location: ' . $current_admin . '', true, 301);
}
}
}
You can try this :)
add_filter( 'admin_menu', 'remove_menus', 99 );
function remove_menus(){
if(!current_user_can('administrator'))
remove_menu_page( 'index.php' ); //dashboard
}
Admin menus and plugin menus are two different. You need to use separate actions to hide admin menus and plugin menus from admin dashboard. Here is how.
// Hide Admin Menus
function remove_menus() {
remove_menu_page( 'plugins.php' );
remove_menu_page( 'users.php' );
remove_menu_page( 'options-general.php' );
}
add_action( 'admin_menu', 'remove_menus' );
// Hide plugin menus
function remove_plugin_menu_pages() {
remove_menu_page( 'edit.php?post_type=acf' );
remove_menu_page( 'wpcf7' );
remove_menu_page( 'itsec' );
remove_menu_page( 'cptui_main_menu' );
remove_menu_page( 'revslider' );
}
add_action( 'admin_init', 'remove_plugin_menu_pages' );
Here's what worked for me. This will only show Menu Items to Admin role & hide for other role(s). If you want to hide for Admin also, then remove the if statement.
// Hide Admin Menus from WP-Dashboard
add_filter( 'admin_menu', 'remove_menus');
function remove_menus(){
if(!current_user_can('administrator')) {
remove_menu_page( 'edit.php?post_type=page' ); //Contact Form7
remove_menu_page( 'edit.php?post_type=portfolio_item' ); //CPT
remove_menu_page( 'wpcf7' ); //Contact Form7
remove_menu_page( 'tools.php' ); //Tools
remove_menu_page( 'vc-welcome' ); //WPBakery Page Builder
}
}
本文标签:
版权声明:本文标题:plugins - Remove dashboard links from wordpress 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745538743a2155082.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论