Hide Adsense/Ads on Admin in Wordpress
Posted on August 30th, 2008 in Google, Programming |
You have wordpress and you put ads on it, like this blog (sorry if you feel its too much, haha), and you want to hide your ads when you and the other admins are viewing the site. Here is a small script that might help you.
Go to the location of your ads, it could be found on your template if you add it manually (if you use plugins your on your own)
For example you add an ads on your sidebar, you can access this page through the admin’s Design Tab -> Theme Editor -> Sidebar (sidebar.php). Enter this code:
<? if(!current_user_can('edit_users')): ?>
Your Ads here
<? endif; ?>
What does this do, it will check if the user can edit users which means it will check if the current user is an admin, another thing to notice here is that i didn’t use curly brackets on PHP’s if, so if you didn’t know yet PHP is quite a messy language, it can have C syntax and some Basic kinda like syntax, usually i use Basic kinda like syntax on view. Why? Coz using the if-endif,for-endfor,foreach-endforeach of it seems to be more readable then curly brackets when combined with html tags.













