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 badges1 Answer
Reset to default 2Yes, 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).
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745331941a4622921.html
评论列表(0条)