12 次查询 耗时 0.054 秒
本文共计1391个字,0条留言,预计阅读时长5分钟
登录/注册
  • 首页
  • >
  • Notes
  • >
  • WordPress主题开发:移除后台菜单选项卡
  • WordPress主题开发:移除后台菜单选项卡

    作者:Misshylsay

    日期:2020年02月15日

    对于一些企业化的定制用户,我们很有必须要对wordpress主题的默认后台菜单选项进行一些修改或是删减比如,如果有新闻的添加改成新闻,那如果对于小工具或是页面功能使用不到的我们需要做一个隐藏或是删减的调整,那我们就需要用到以下的代码功能来满意我们的小需求。

    下面代码添加到wordpress主题的funtion.php文件内,不同的名称代表后台不同的菜单选项链接。

    'index.php', // Dashboard仪盘表
    'edit.php?post_type=custom_type_one', // Custom type one
    'edit.php?post_type=custom_type_two', // Custom type two
    'edit.php?post_type=custom_type_three', // Custom type three
    'edit.php?post_type=custom_type_four', // Custom type four
    'edit.php?post_type=custom_type_five', // Custom type five
    'separator1', // First separator
    'edit.php?post_type=page', // Pages页面
    'edit.php', // Posts文章
    'upload.php', // Media多媒体
    'link-manager.php', // Links链接
    'edit-comments.php', // Comments评论
    'separator2', // Second separator
    'themes.php', // Appearance主题
    'plugins.php', // Plugins插件
    'users.php', // Users用户
    'tools.php', // Tools工具
    'options-general.php', // Settings设置
    'separator-last', // Last separator

    这里是我们真正要用到的wordpress后台选项菜单移除代码,我们需要用到 remove_menu_page(‘*’);对wordpress后台选项做调整。

    /*remove_menu_page_wp3.1*/
    function yg_remove_menu_page() {
      remove_menu_page('themes.php');  // 移除 "外观"
      remove_menu_page('plugins.php'); // 移除 "插件"
      remove_menu_page('tools.php');   // 移除 "工具"
    }
    add_action( 'admin_menu', 'yg_remove_menu_page' );

    除了主菜单选项外我们还可以对二次菜单进行调整,具体的代码样式如下。

    /*remove_submenu_page_wp3.1*/
    function yg_remove_submenu_page() {
      remove_submenu_page( 'index.php', 'update-core.php' ); //移除“控制面板”下的“更新”
    }
    if ( is_admin() ) {
      add_action('admin_init','yg_remove_submenu_page');
    }

    这些都是我在开发本站博客主题过程中积累的经验,在这里与大家分享。

    “WordPress主题开发:移除后台菜单选项卡”共有0条评论

    发表评论

    B em del U Link Code Quote