WordPress 网站屏蔽删除后台无用项的方法

2023年2月16日05:53:55 发表评论
腾讯云正在大促:点击直达 阿里云超级红包:点击领取
免费/便宜/高性价比服务器汇总入口(已更新):点击这里了解

WordPress 网站屏蔽删除后台无用项的方法

WordPress 网站屏蔽删除后台无用项的方法。WordPress 后台很多模块有时并不需要,使用下面的代码可以将它们屏蔽掉。

1、根据需要,将下面代码添加到当前主题functions.php模板文件中:

2、屏蔽左侧菜单:

  1. function remove_menus() {    global $menu;    $restricted = array(        __('Dashboard'),        __('Posts'),        __('Media'),        __('Links'),        __('Pages'),        __('Appearance'),        __('Tools'),        __('Users'),        __('Settings'),        __('Comments'),        __('Plugins')    );    end ($menu);    while (prev($menu)){        $value = explode(' ',$menu[key($menu)][0]);        if(strpos($value[0], '<') === FALSE) {            if(in_array($value[0] != NULL ? $value[0]:"" , $restricted)){                unset($menu[key($menu)]);            }        }else {        $value2 = explode('<', $value[0]);            if(in_array($value2[0] != NULL ? $value2[0]:"" , $restricted)){                unset($menu[key($menu)]);            }        }    }}if (is_admin()){    // 屏蔽左侧菜单    add_action('admin_menu', 'remove_menus');}  

3、删除子菜单

  1. function remove_submenu() {    // 删除”设置”下面的子菜单”隐私”    remove_submenu_page('options-general.php', 'options-privacy.php');    // 删除”外观”下面的子菜单”编辑”    remove_submenu_page('themes.php', 'theme-editor.php');}if (is_admin()){    //删除子菜单    add_action('admin_init','remove_submenu');}  

4、屏蔽后台更新模块

  1. function wp_hide_nag() {    remove_action( 'admin_notices', 'update_nag', 3 );}add_action('admin_menu','wp_hide_nag');  

5、屏蔽 WP 后台“显示选项”和“帮助”选项卡

  1. function remove_screen_options(){ return false;}    add_filter('screen_options_show_screen', 'remove_screen_options');    add_filter( 'contextual_help', 'wpse50723_remove_help', 999, 3 );    function wpse50723_remove_help($old_help$screen_id$screen){    $screen->remove_help_tabs();    return $old_help;}  

6、屏蔽后台仪表盘无用模块

  1. function example_remove_dashboard_widgets() {    // Globalize the metaboxes array, this holds all the widgets for wp-admin    global $wp_meta_boxes;    // 以下这一行代码将删除 "快速发布" 模块    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);    // 以下这一行代码将删除 "引入链接" 模块    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);    // 以下这一行代码将删除 "插件" 模块    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);    // 以下这一行代码将删除 "近期评论" 模块    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);    // 以下这一行代码将删除 "近期草稿" 模块    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);    // 以下这一行代码将删除 "WordPress 开发日志" 模块    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);    // 以下这一行代码将删除 "其它 WordPress 新闻" 模块    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);    // 以下这一行代码将删除 "概况" 模块    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);}add_action('wp_dashboard_setup', 'example_remove_dashboard_widgets' );  

7、屏蔽后台页脚版本信息

  1. function example_remove_dashboard_widgets() {    // Globalize the metaboxes array, this holds all the widgets for wp-admin    global $wp_meta_boxes;    // 以下这一行代码将删除 "快速发布" 模块    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);    // 以下这一行代码将删除 "引入链接" 模块    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);    // 以下这一行代码将删除 "插件" 模块    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);    // 以下这一行代码将删除 "近期评论" 模块    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);    // 以下这一行代码将删除 "近期草稿" 模块    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);    // 以下这一行代码将删除 "WordPress 开发日志" 模块    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);    // 以下这一行代码将删除 "其它 WordPress 新闻" 模块    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);    // 以下这一行代码将删除 "概况" 模块    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);}add_action('wp_dashboard_setup', 'example_remove_dashboard_widgets' );  

8、屏蔽后台左上LOGO

  1. function annointed_admin_bar_remove() {        global $wp_admin_bar;        /* Remove their stuff */        $wp_admin_bar->remove_menu('wp-logo');}add_action('wp_before_admin_bar_render', 'annointed_admin_bar_remove', 0);  

1、阿里云产品最新优惠领取地址:立即前往

2、阿里云服务器优惠券领取地址优惠购买地址:点击前往

3、阿里云最新优惠活动地址汇总,共16个,地址:点击前往

4、同配置云产品腾讯云相对便宜,先点此一键领取2860元无门槛满减券(老用户换QQ登陆,同一实名享新人特价),再点此进入腾讯云活动页面12年老码农建议:服务器升级、复购、续费贵,数据迁移也麻烦,建议用好新人优惠资格,买多年,配置一次性到位,后期省事又省钱。

腾讯云正在大促:点击 https://2bcd.com/go/tx/进入最新活动页】领取无门槛代金券,附云服务器价格表,2核2G4M轻量应用服务器99元1年,新老用户都可以买,可以享受1次续费99元一年、135元15个月、三年560元,MySQL云数据库59元1年起,2核2G3M配置82元1年,2核4G5M配置188元一年、3年900元,4核8G12M轻量服务器880元15个月,8核16G配置1890元15个月,更多16核32G28M带宽和云服务器CVM标准型S5、GPU服务器、CVM标准型SA2租用优惠价格如下,可以 点此进入最新活动页 查看当前最新的优惠券和活动信息。还可以领下10元无门槛代金券:点此直达 阿里云限量超级红包:点击领取】5亿上云补贴和2088元满减代金券,阿里云服务器租用费用最新价格表【点击了解】,最便宜轻量应用服务器2核2G3M带宽82元1年,ECS云服务器2核2G3M带宽99元一年,ECS u1实例2核4G5M带宽优惠价格199元一年,香港30M带宽轻量服务器24元1个月、288元一年,4核8G服务器706元一年,ECS云服务器4核16G10M带宽30元1个月、90元3个月,云服务器8核32G10M带宽109元1个月、327元3个月。阿里云产品最高降价55%,点击 https://2bcd.com/go/aliyun/ 进入最新活动页了解。 腾讯云续费贵,一次性买3年/5年,免得续费贵。3年轻量 2核2G 4M 560元;3年轻量 2核4G 5M 3年900元,活动入口:点击前往(下拉到“爆品专区”即可看到)。 老用户享新人优惠的方法:用Qq登录、1人可注册3个新账号/用家人朋友的身份注册新号(点击注册新账号)。

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: