Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have modified the buddpress admin bar by creating the following plugin which adds a simple text link to the bar:

function bp_adminbar_currentsite_menu() {

global $bp;
?>
<li>
<!-- Insert your link url or relative url, and your link text below -->
<a href="http://EXAMPLE.COM">EXAMPLE LINK TEXT</a>
</li>
<?php
}
// Call The Function Above
add_action('bp_adminbar_menus', 'bp_adminbar_currentsite_menu', 999);

However, I do NOT want the above link to be shown when logged into the wordpress admin backend (so for example when an admin is editing a post). I thought about just doing a php_self check to see if it contained "/wp-admin/" but figured that there has to be a more elegant wordpress/buddypress hook here.

How can I get the above code to only show when you are viewing a normal blog page, NOT in the admin area?

Thanks

share|improve this question

1 Answer 1

up vote 0 down vote accepted

You ca use the conditional tag is_admin() to check if you are on the front-end or back-end like this:

function bp_adminbar_currentsite_menu() {
    global $bp;
    if (!is_admin()){
        ?>
        <li>
        <!-- Insert your link url or relative url, and your link text below -->
        <a href="http://EXAMPLE.COM">EXAMPLE LINK TEXT</a>
        </li>
        <?php
    }
}
// Call The Function Above
add_action('bp_adminbar_menus', 'bp_adminbar_currentsite_menu', 999);
share|improve this answer
    
thanks, is_admin() is exactly what I was looking for. I added the if statement to the "add_action" instead, just FYI, thanks again. I also asked the same question on SO here if you want to copy and paste your answer: stackoverflow.com/questions/5461330/… –  themerlinproject Mar 29 '11 at 2:36

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.