最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

customization - Admin only menupage

programmeradmin0浏览0评论

Is it possible to show a menu item If only admin is logged in)

For any other user the menu item does not appear.

For example: if there are a few pages that have shortcodes or other functionality exampled to show how to build toggles etc, but only want the admin to be able to see them. These pages generally come with pre-built themes and show the admin how to build pages within the site.

By hiding the menu items, a series of pages can be "hidden" from a user but allow the admin to see them to be able to build pages, without having to remove them entirely from the site

:P make sense?

Is it possible to show a menu item If only admin is logged in)

For any other user the menu item does not appear.

For example: if there are a few pages that have shortcodes or other functionality exampled to show how to build toggles etc, but only want the admin to be able to see them. These pages generally come with pre-built themes and show the admin how to build pages within the site.

By hiding the menu items, a series of pages can be "hidden" from a user but allow the admin to see them to be able to build pages, without having to remove them entirely from the site

:P make sense?

Share Improve this question asked Jul 12, 2013 at 20:39 idarylidaryl 111 silver badge2 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

Yes, it is possible.

You could use wp_nav_menu_objects or wp_nav_menu_items hooks to add your filter function.

function my_hide_menu_items($objects) {
    if ( is_admin() ) return $objects;

    foreach ( $objects as $k=>$object ) {
        if ( YOUR CONDITION ) {  // if $object shouldn't be displayed
            unset($objects[$k]);
        }
    }
    return $objects;
}
add_filter('wp_nav_menu_objects', 'my_hide_menu_items', 10, 2);

You can also use this plugin: http://wordpress/plugins/menu-items-visibility-control/ (I haven't tested it, so I'm not sure if it really works).

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论