WordPress.org

Forums

How to remove/hide ads per user basis (4 posts)

  1. wpmhweb
    Member
    Posted 2 years ago #

    Hello,

    I am need to remove/hide ads from specific users when they are logged in. There is anyway to do this?

    I tried this:
    <?php global $current_user; get_currentuserinfo(); if ($current_user->user_level == 10 ) { ?> // dont show ads <?php } else { ?> // show ads - put ad code here <?php } ?>

    but it doesn't work for me, I am administrator and I still see ads with this code.

    Thanks

  2. Andrew Bartel
    Member
    Posted 2 years ago #

    Use current_user_can() and check it against something only an administrator can do like activate plugins.

    http://codex.wordpress.org/Function_Reference/current_user_can

  3. wpmhweb
    Member
    Posted 2 years ago #

    Thanks,

    I am giving it a try!

  4. wpmhweb
    Member
    Posted 2 years ago #

    Worked like a charm!

    This is what I did:

    <?php if (current_user_can( 'activate_plugins' )) { ?>
                  //no ads
     <?php } else { ?>
    
            //ad block shows
    
           <?php } ?>

    Thank you so much!

Topic Closed

This topic has been closed to new replies.

About this Topic