WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hello have been looking at this for quite a while and cant seem to resolve it was hoping someone more familiar with the wordpress core and php could share some idea.

What I want to accomplish essentially is to Hide a div that permits buddypress users (the subscrivers) from adding new topics to a group forum. But I dont want this to be hidden from all the forums just 1 of them. So I need 2 pieces 1 that determines whether someone is a subscriber or an admin. so its only hidden to the subscriber. and 2 that it hides it from only 1 page.

Example of potential code just need to fit it together (all code would go in the functions.php unless there is another way)

<?php /* If this is the frontpage */ if ( is_home() || is_page() ) { ?>
have info link or whatever in here
<?php } ?> 

Thats for the frontpage but similarly you can get the page by ID

For role I saw this


I would assume there is a


and from there you can do an if in the php something like if is_subscriber() and is_page( 42 ) call .js file and from there add a class that hides the div I want to hide by jquery

Thats as far as I got from what I know and looking around. I would greatly appreciate any and all assistance.

share|improve this question

migrated from stackoverflow.com May 15 '12 at 2:54

This question came from our site for professional and enthusiast programmers.

FYI, is_admin() checks for whether the user is on the Dashboard or administration panel, not whether the user is the adminastrator of the site. – mrwweb May 15 '12 at 3:10

Just hiding a div is insecure - they can easily unhide it by editing the source or executing some Javascript in the browser's URL bar. I believe this may be what you're looking for:

if (current_user_can(‘subscriber’)){

[html here]


Source: How to Use WordPress to Display Content Depending on a User’s Level

share|improve this answer

If you know the ID of the page you want to hide the button on, you can use is_page() in the loop. Outside of the loop, use this:

global $post;
$post_id = $post->ID;

While @JamesF's answer should work, using roles is considered to be less-stable than testing against a specific capability. You can find a table comparing roles and capabilities on the Codex. The only capability subscribers have is read, so you'd test against that.

Your final code, would then look like this:

global $post;
$post_id = $post->ID;
if( $post_id = 42 && current_user_can( 'read' ) {
    // do stuff

The final step is where to put this. Unless you're programmatically adding the button via functions.php, you'll be looking to wrap the button (aka "// do stuff") in the above code in an existing theme file. That will require tracking down the button in your theme, or possibly finding where it's made via a PHP function in BuddyPress.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.