【问题标题】:Change menu items labels in wordpress admin area?更改 wordpress 管理区域中的菜单项标签?
【发布时间】:2014-09-20 05:20:15
【问题描述】:

有没有办法更改管理区域内菜单项的标签?就像您注册一个新的自定义帖子类型时一样,您可以为其指定每个标签,但为默认菜单项。

提前致谢!

【问题讨论】:

    标签: wordpress wordpress-theming


    【解决方案1】:
    add_filter( 'gettext', 'change_post_to_article' );
    add_filter( 'ngettext', 'change_post_to_article' );
    
    function change_post_to_article( $translated ) 
    {  
        $translated = str_replace( 'Post', 'Article', $translated );
        $translated = str_replace( 'post', 'article', $translated );
        return $translated;
    }
    

    还有另一种方法可以做到这一点,有关更多信息,请查看answer

    【讨论】:

    • 效果很好。这会改变这个词出现在翻译中的任何地方吗?还是只是菜单?
    【解决方案2】:

    最好的解决方案是这样,只需写在你的functions.php或插件文件中

    function change_post_menu_label() {
        global $menu;
        global $submenu;
        $menu[70][0] = 'Articles';
        $submenu['user-edit.php'][5][0] = 'Articles';
        $submenu['user-edit.php'][10][0] = 'Add Articles';
        echo '';
    }
    function change_post_object_label() {
            global $wp_post_types;
            $labels = &$wp_post_types['users']->labels;
            $labels->name = 'Articles';
            $labels->singular_name = 'Article';
            $labels->add_new = 'Add Article';
            $labels->add_new_item = 'Add Article';
            $labels->edit_item = 'Edit Article';
            $labels->new_item = 'Article';
            $labels->view_item = 'View Article';
            $labels->search_items = 'Search Articles';
            $labels->not_found = 'No Articles found';
            $labels->not_found_in_trash = 'No Articles found in Trash';
    }
    add_action( 'init', 'change_post_object_label' );
    add_action( 'admin_menu', 'change_post_menu_label' );
    

    【讨论】:

      【解决方案3】:

      仅供参考,在我当前公司的博客上对该代码的更新参考:http://www.get10up.com/blog/2011/03/customizing-wordpress-admin/

      您可以在 PHP5 中使用 str ireplace 来避免两次调用。

      【讨论】:

        【解决方案4】:

        // 将插件重命名为 Apps Store

        function rename_plugin_menu() {  
            global $menu;       
            $menu[65][0] = 'Apps Store'; // Change Users to Customers main id
        }  
        add_action( 'admin_menu', 'rename_plugin_menu' );  
        

        【讨论】:

          猜你喜欢
          • 2013-09-16
          • 2021-09-26
          • 1970-01-01
          • 2017-08-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-08
          相关资源
          最近更新 更多