Monmonja Programming Blog

August 30, 2008

Hide Adsense/Ads on Admin in WordPress

Filed under: Google,Programming — Tags: , — admin @ 10:58 am

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; ?>

SecondSpin.com

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.

Share and Enjoy:
  • Digg
  • Reddit
  • Slashdot
  • del.icio.us
  • StumbleUpon
  • TwitThis
  • Fark
  • Facebook
  • Technorati
  • Sphinn
  • Furl
  • Google Bookmarks
  • Mixx

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress

Monmonja Programming Blog is Digg proof thanks to caching by WP Super Cache