php - How to make an HTML element hidden and viewable only for certain role only in wordpress?
Newbie wordpress/php student. I want to make a certain element viewable only for a certain user-role in wordpress and hidden for all normal subscribers/non-subscribers.
Its for a property page on a real estate website. I want to make a specific tab element hidden so only for certain users(agent user role) to be able to see.(The element will contain information such as property owners phone number. I will take the 'floorplan' tab on the property page and change it to 'owner info' tab.
Answer
Solution:
It's tough to answer precisely without seeing the PHP template code for these tabs, but in general, this is as simple as putting that tab's HTML inside a PHP conditional.
// your code that checks if this home is owned by the current user
// var $owner_viewing_property = is_owner_viewing();
<ul class="tabs">
<li class="tab">Features</li>
<? if ($owner_viewing_property) { ?>
<li class="tab">Owner Info</li>
<? } else { ?>
<li class="tab">Floor Plans</li>
<? } ?>
</ul>
Source