The MU forums have moved to WordPress.org

Exclude Admin Bar from Main Page (12 posts)

  1. annag
    Member
    Posted 17 years ago #

    I've installed the admin bar and it's working fine but I was wondering if there was a way to exclude it from the main page/blog of the site? I'm using a special theme just for the main blog so is there is a code I can insert in that theme to hide the bar? I just want it to show on the users' blogs.

    I apologize in advance if this has been answered elsewhere. I searched but couldn't find anything about it.

  2. Ovidiu
    Member
    Posted 17 years ago #

    you mean you want to exclude it from your main blog, not the main page?

    if so you would need an if statement something like if blog_id == 1 (your main blog is always #1) die ? and else => display admin bar? or make it an if blog_id != 1 display admin bar...

    I am no php guru, you'll have to work your way from here alone...I usually analyze other plugins and copy code from there.

  3. annag
    Member
    Posted 17 years ago #

    The main blog is also the main page of the site and I'm using pages on the main blog to build all the non-blog pages of the site, so I don't want the main page and all of those pages to have the blog admin bar.

    So it would be something like this?

    if blog_id == 1 die ? and else =>

    I'm not sure I understand ...

    I've been using Movable Type for three years and am still learning WordPress code.

  4. annag
    Member
    Posted 17 years ago #

    So I was just looking around and figured the code should look something like this, but I'm having trouble figuring out the whole thing. There isn't anything in Wordpress documentation about how to write if else statements as I can see? Were you saying I should put "die" to not show it?

    if( $blog_id == 1 ) {

    die

    } else {

    display_admin_bar();

  5. Ovidiu
    Member
    Posted 17 years ago #

    try this:

    if( $blog_id == 1 ) {

    die();

    } else {

    display_admin_bar();

    like I said I am just stabbing in the dark but if you poke around long enough you're bound to hit something... :-)

  6. annag
    Member
    Posted 17 years ago #

    What you posted didn't work so I searched PHP sites trying to figure out the language. I tried this:

    if( $blog_id == 1 ) {

    return FALSE;

    }else {

    return TRUE;
    }

    That actually worked! The bar no longer shows on Blog #1 and it shows on all other blogs. The only problem? It shows on the other blogs with no CSS, so the menu items are just going down the left side of the page.

    Anyone know how to fix that? I'm almost there, darnit!!

  7. suleiman
    Member
    Posted 17 years ago #

    why not just remove the footer do action from your footer.php file on the main blog? Unless you've got other plugins you need to use which latch on to that you can just take it out of your main blog and the admin bar will no longer load on that blog.

  8. annag
    Member
    Posted 17 years ago #

    Thanks suleiman, that worked. How do I know if other plugins latch into the footer do action?

  9. lunabyte
    Member
    Posted 17 years ago #

    Removing that isn't a good idea, really.

    The correct option, aside from the hacks pointing you in the wrong direction, would be this.

    Open the mu admin bar php file.

    At the top you will see this:

    <?php
    
    /* <WP Plugin Data>

    Add the following in between the two:

    if ( !defined("ABSPATH) ) {
         die("I don't think so, Tim.");
    }
    
    global $blog_id;
    
    if ( $blog_id == 1 ) {
         return;
    }

    So now, the top should look like this:

    <?php
    
    if ( !defined("ABSPATH) ) {
         die("I don't think so, Tim.");
    }
    
    global $blog_id;
    
    if ( $blog_id == 1 ) {
         return;
    }
    
    /* <WP Plugin Data>

    What this does, as an explanation, is first it makes sure MU called the file. If it didn't, and someone is trying to access it directly to insert an injection, it executes the php function die(). The message in between may be customized, that just happens to be my style of telling them to stick it.

    Second, it calls the globally available variable, $blog_id.

    Next, it checks for that value equaling 1. If it does, it simply does nothing. If it's not blog_id 1, then it runs as normal.

  10. suleiman
    Member
    Posted 17 years ago #

    they only will if you tell them to. I think the Anarchy Media Player Plugin is one of them, and so is the Google Analytics plugin.

    The best way to find out is to view your source without the footer code removed, and then view it again with it removed.

  11. Bike
    Member
    Posted 17 years ago #

    Hi Lunabyte, when adding your code I get the following error:

    Parse error: syntax error, unexpected T_STRING in public_html/wp-content/mu-plugins/mu-admin-bar.php on line 4

    (line 4 would be the "die" line.)
    sorry for my php ingnorance, but what is missing/too much?

    Thanks

  12. lunabyte
    Member
    Posted 17 years ago #

    if ( !defined("ABSPATH") ) {

About this Topic