Need some php logic help

I’m using the following code in a mu-plugin to setup some styles for my BuddyBar across my multisite network. It gives me a customized bar that goes across the top of all my user’s sites.

function global_tt_bar() {
echo '<link rel="stylesheet" type="text/css" href="' .plugins_url('global-tt-bar.css', __FILE__). '">';
}

add_action('wp_footer', 'global_tt_bar', 1);

I need some help in adding some logic to it so that it doesn’t call the css file on the front of the main site (blog ID: 1). I want to use my theme’s built in BuddyBar styles for that.

It’s just a couple lines of php code that I need, but I’m not a coder and everytime I tried to modify this, I ended up breaking everything.

Can someone take a look and help me out, please?

  • Han
    • The Crimson Coder

    Hiya, please try this

    function global_tt_bar() {
    if ( !is_home() && !is_main_site() ) {
    echo '<link rel="stylesheet" type="text/css" href="' .plugins_url('global-tt-bar.css', __FILE__). '">';
    }
    }

    add_action('wp_footer', 'global_tt_bar', 1);

    Let me know if it doesn’t work

    -Hence

  • Saunt Valerian
    • The Bug Hunter

    bugger all – I thought it worked, but forgot to expire the cached resouces at the CDN while I was working on it.

    Turns out that it doesn’t work – when the cache expired I saw that no styles were being applied at all. Didn’t get an error message, but none of the styles were being called.

    Still need work on this.

    For the time being, I’ve turned off my CDN while I work on this. It always causes me a headache when working styling stuff.

  • Han
    • The Crimson Coder

    Sorry, the logic is incorrect. This is the correct one.

    function global_tt_bar() {
    if ( !is_home() || !is_main_site() ) {
    echo '<link rel="stylesheet" type="text/css" href="' .plugins_url('global-tt-bar.css', __FILE__). '">';
    }
    }

    add_action('wp_footer', 'global_tt_bar', 1);

    Please try and let me know =)

  • Saunt Valerian
    • The Bug Hunter

    I haven’t tried it yet, hopefully I’ll get a chance later tonight, but that code there looks like it says

    “if it is the main site , then call the stylesheet”

    What it needs to do is

    “if it is the main site, do not call the stylesheet. If is not the main site, call the stylesheet.”

    The stylesheet is used to control the display of the Buddybar on all the subsites on the network. The main site uses its own internal css from its theme to control the buddybar.

    In essence, the subsites get a rather plain, but branded buddybar that is styled to work with all subsites regardless of theme (that’s what this referenced stylesheet does). The main site’s BuddyBar is customized internally with it’s own css to blend with the theme of the main site.

  • Han
    • The Crimson Coder

    Hiya,

    that code there looks like it says

    “if it is the main site , then call the stylesheet”

    No, it says “don’t call the stylesheet if it’s the front page of main site

    What it needs to do is

    “if it is the main site, do not call the stylesheet. If is not the main site, call the stylesheet.”

    If you don’t want to call the css if is the main site (means all pages of main site), here the script

    function global_tt_bar() {
    if (!is_main_site() ) {
    echo '<link rel="stylesheet" type="text/css" href="' .plugins_url('global-tt-bar.css', __FILE__). '">';
    }
    }

    add_action('wp_footer', 'global_tt_bar', 1);

  • Saunt Valerian
    • The Bug Hunter

    Yes! That last one there was the correct one.

    I did just discover a related problem and was wondering if you could also help with that. The styles are not being applied to domain-mapped subsites. Those are displaying the default buddybar. Is it even possible to control that with the bit of code with some more logic?

  • Saunt Valerian
    • The Bug Hunter

    It’s not just network activated, I’m using it as a mu-plugin. My thinking is that it should be on all of our subsites, and it works great on anything that is not domain mapped.

    This is one of our domain mapped sites: http://sororiteasisters.com

    The styles aren’t being applied to the buddybar there, and the stylesheet isn’t being called.

    This is one of our non-mapped sites and you can see our styled buddybar at the top. In the source code, the stylesheet is being loaded (it loads at the bottom since it is called in the footer when the buddybar is called.) It shows up in line 1127 (using Chrome) in the source code as /wp-content/mu-plugins/global-tt-bar.css

    http://lahikmajoedrinkstea.teatra.de/

    That bit isn’t present in the mapped site. I can’t even begin to imagine what the fix might be (though I could always change the css in the core BP file, but I’m trying to keep it all upgrade friendly).

  • Han
    • The Crimson Coder

    Ok, I found the problem. Please modify the function as follow

    function global_tt_bar() {
    if (!is_main_site() ) {
    echo '<link rel="stylesheet" type="text/css" href="/wp-content/mu-plugins/global-tt-bar.css">';
    }
    }

    add_action('wp_footer', 'global_tt_bar', 1);

  • rozani
    • Site Builder, Child of Zeus

    wow.

    Thanks really. I really don’t know is_main_site is all about.

    Is is_main_site means the main site the user must login?

    I’m very clear on is_front_page because the hook does not require user to login.

    I’m pretty not sure for is_main_site.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.