Skip to content Skip to sidebar Skip to footer

Hiding DIV From Menu Based On User Role / Capabilities Wordpress

I have a wordpress site with 2 user roles, customer and vendor. I want to hide the Vendor Dashboard from the menu bar from Customers. The code for this theme is in the header-aside

Solution 1:

You can check the user roles inside the WP_User object, which is returned by the function wp_get_current_user (). So you may show Dashboard only for Vendor by that code:

<?php 
$user = wp_get_current_user();
if ( in_array( 'vendor', $user->roles ) ) {
?>
    <!-- Any HTML what you need to hide from "Customers" and show for "Vendor" -->
    <div>Vendor Dashboard</div>
<?php 
}
?>

Post a Comment for "Hiding DIV From Menu Based On User Role / Capabilities Wordpress"