i want to hide ads for logged in user (subscribers). im using a plugin called “private” that generates shortcodes. i found the code i should use but dont know how to put it in my single.php. My single post is custom made so i cant use the rich editor.
the one i want to use…
[private role=”subscriber”]Content goes here[/private]
and i want to put this code in the middle position of my short code.
<div id="M589567ScriptRootC925056"></div> <script src="https://jsc.adskeeper.co.uk/a/n/anime-tv.fun.925056.js" async></script>
Advertisement
Answer
You do not have to use [private]
short codes to hide divs
or ads in your case from logged in users.
Just use WordPress native current_user_can()
function to target specific user roles like this in PHP file
if (current_user_can('subscriber')) { //Hide something } else { //Show Something }
You can do something if you want to hide something from all logged in users
if (is_user_logged_in) { //Hide something } else { //Show Something }
This code goes into your working php
file or active theme function.php