php - How to make an HTML element hidden and viewable only for certain role only in wordpress?
Get the solution ↓↓↓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>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: script cache:clear returned with error code 255
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.