Skip to main content
deleted 713 characters in body
Source Link
Corbula
  • 169
  • 2
  • 12
  • 25

In my menu i've got some menu items that i don't want to show to people who aren't logged in. One of these i only want to show to logged in users of a certain roles the other to everyone logged in.

So one of them is called 'My Printer'. This should be visible to everyone that is logged in.

The other is called 'Partners'. This should only be visible to users with the partner role.

I've tried using Role Scoper but i find it very difficult to use and it doesn't make a lot of sense. It also interferes with a lot of other things as well which i don't need.

Is there anyway i can hide menu items based on their role?

Thanks

EDIT

This is the code in my header.php file for the menu.

<div id="primary-menu">
    <?php
    if ( function_exists('wp_nav_menu') ) {
        wp_nav_menu( array(
        'theme_location' => 'primary',
        'sort_column' => 'menu_order',
        'menu_class' => 'sf-menu',
        'fallback_cb' => 'default_menu'
        ));
    }
    ?>
</div><!-- /primary-menu -->

If i use this from the answer below. It will show the text above the menu.

<?php
    if ( is_user_logged_in() ) {
            if(current_user_can('edit_published_posts')) {
            echo 'Welcome, Partner!';
            }
            else {
            echo 'Welcome, registered user!';
            }
    } 
    else {
        echo 'Welcome, visitor!';
    }
    ?>

I've created the menu using the admin and placed that menu in a theme location. The menu items i want to hide are in this menu.

Thanks for the 2 answers below, but neither achieve what i'm after.

In my menu i've got some menu items that i don't want to show to people who aren't logged in. One of these i only want to show to logged in users of a certain roles the other to everyone logged in.

So one of them is called 'My Printer'. This should be visible to everyone that is logged in.

The other is called 'Partners'. This should only be visible to users with the partner role.

I've tried using Role Scoper but i find it very difficult to use and it doesn't make a lot of sense. It also interferes with a lot of other things as well which i don't need.

Is there anyway i can hide menu items based on their role?

Thanks

EDIT

This is the code in my header.php file for the menu.

<div id="primary-menu">
    <?php
    if ( function_exists('wp_nav_menu') ) {
        wp_nav_menu( array(
        'theme_location' => 'primary',
        'sort_column' => 'menu_order',
        'menu_class' => 'sf-menu',
        'fallback_cb' => 'default_menu'
        ));
    }
    ?>
</div><!-- /primary-menu -->

If i use this from the answer below. It will show the text above the menu.

<?php
    if ( is_user_logged_in() ) {
            if(current_user_can('edit_published_posts')) {
            echo 'Welcome, Partner!';
            }
            else {
            echo 'Welcome, registered user!';
            }
    } 
    else {
        echo 'Welcome, visitor!';
    }
    ?>

I've created the menu using the admin and placed that menu in a theme location. The menu items i want to hide are in this menu.

In my menu i've got some menu items that i don't want to show to people who aren't logged in. One of these i only want to show to logged in users of a certain roles the other to everyone logged in.

So one of them is called 'My Printer'. This should be visible to everyone that is logged in.

The other is called 'Partners'. This should only be visible to users with the partner role.

I've tried using Role Scoper but i find it very difficult to use and it doesn't make a lot of sense. It also interferes with a lot of other things as well which i don't need.

Is there anyway i can hide menu items based on their role?

Thanks

EDIT

I've created the menu using the admin and placed that menu in a theme location. The menu items i want to hide are in this menu.

Thanks for the 2 answers below, but neither achieve what i'm after.

added 929 characters in body
Source Link
Corbula
  • 169
  • 2
  • 12
  • 25

In my menu i've got some menu items that i don't want to show to people who aren't logged in. One of these i only want to show to logged in users of a certain roles the other to everyone logged in.

So one of them is called 'My Printer'. This should be visible to everyone that is logged in.

The other is called 'Partners'. This should only be visible to users with the partner role.

I've tried using Role Scoper but i find it very difficult to use and it doesn't make a lot of sense. It also interferes with a lot of other things as well which i don't need.

Is there anyway i can hide menu items based on their role?

Thanks

EDIT

This is the code in my header.php file for the menu.

<div id="primary-menu">
    <?php
    if ( function_exists('wp_nav_menu') ) {
        wp_nav_menu( array(
        'theme_location' => 'primary',
        'sort_column' => 'menu_order',
        'menu_class' => 'sf-menu',
        'fallback_cb' => 'default_menu'
        ));
    }
    ?>
</div><!-- /primary-menu -->

If i use this from the answer below. It will show the text above the menu.

<?php
    if ( is_user_logged_in() ) {
            if(current_user_can('edit_published_posts')) {
            echo 'Welcome, Partner!';
            }
            else {
            echo 'Welcome, registered user!';
            }
    } 
    else {
        echo 'Welcome, visitor!';
    }
    ?>

I've created the menu using the admin and placed that menu in a theme location. The menu items i want to hide are in this menu.

In my menu i've got some menu items that i don't want to show to people who aren't logged in. One of these i only want to show to logged in users of a certain roles the other to everyone logged in.

So one of them is called 'My Printer'. This should be visible to everyone that is logged in.

The other is called 'Partners'. This should only be visible to users with the partner role.

I've tried using Role Scoper but i find it very difficult to use and it doesn't make a lot of sense. It also interferes with a lot of other things as well which i don't need.

Is there anyway i can hide menu items based on their role?

Thanks

In my menu i've got some menu items that i don't want to show to people who aren't logged in. One of these i only want to show to logged in users of a certain roles the other to everyone logged in.

So one of them is called 'My Printer'. This should be visible to everyone that is logged in.

The other is called 'Partners'. This should only be visible to users with the partner role.

I've tried using Role Scoper but i find it very difficult to use and it doesn't make a lot of sense. It also interferes with a lot of other things as well which i don't need.

Is there anyway i can hide menu items based on their role?

Thanks

EDIT

This is the code in my header.php file for the menu.

<div id="primary-menu">
    <?php
    if ( function_exists('wp_nav_menu') ) {
        wp_nav_menu( array(
        'theme_location' => 'primary',
        'sort_column' => 'menu_order',
        'menu_class' => 'sf-menu',
        'fallback_cb' => 'default_menu'
        ));
    }
    ?>
</div><!-- /primary-menu -->

If i use this from the answer below. It will show the text above the menu.

<?php
    if ( is_user_logged_in() ) {
            if(current_user_can('edit_published_posts')) {
            echo 'Welcome, Partner!';
            }
            else {
            echo 'Welcome, registered user!';
            }
    } 
    else {
        echo 'Welcome, visitor!';
    }
    ?>

I've created the menu using the admin and placed that menu in a theme location. The menu items i want to hide are in this menu.

edited title
Link
Corbula
  • 169
  • 2
  • 12
  • 25

Hide nav menu items for visitors and filter based on role

Source Link
Corbula
  • 169
  • 2
  • 12
  • 25
Loading