Saunt Valerian
Expert
Member of the Month
Member Likes (0)
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?

Responses (19)
Lifetime Member (joined September 2010) Likes (0)
Hiya, please try this
Let me know if it doesn't work
-Hence
Sales & Support Pro (joined March 2010) Likes (0)
I didn't know about is_main_site! Nice one!
Member (joined February 2011) Likes (0)
It seems to have worked very well, thank you!
Member (joined February 2011) Likes (0)
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.
Sales & Support Pro (joined March 2010) Likes (0)
How about using get_blog_details?
Lifetime Member (joined September 2010) Likes (0)
Sorry, the logic is incorrect. This is the correct one.
Please try and let me know =)
Member (joined February 2011) Likes (0)
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.
Lifetime Member (joined September 2010) Likes (0)
Hiya,
No, it says "don't call the stylesheet if it's the front page of main site"
If you don't want to call the css if is the main site (means all pages of main site), here the script
Member (joined February 2011) Likes (0)
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?
Lifetime Member (joined September 2010) Likes (0)
Hi Saunt,
It should be applied to all subsites if you network activate. Do you see the stylesheet when you view source code?
Lifetime Member (joined September 2010) Likes (0)
maybe I misunderstood you request. You don't want the styles being applied to domain-mapped subsites?
Member (joined February 2011) Likes (0)
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).
Member (joined February 2011) Likes (0)
also, yes, I do want it applied to both mapped and non-mapped sites. Basically, all the subsites on the network.
Lifetime Member (joined September 2010) Likes (0)
odd, I am using another domain mapping plugin and it works for me. But I don't think it conflict with the mapping plugin...
Lifetime Member (joined September 2010) Likes (0)
Ok, I found the problem. Please modify the function as follow
Member (joined May 2011) Likes (0)
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.
Lifetime Member (joined September 2010) Likes (0)
nope. check this http://goo.gl/s0JIw
Member (joined February 2011) Likes (0)
Riyaku - Thank you! That was brilliant!
it works perfectly now on mapped and non-mapped sites. You've solved a problem for me that was holding back development. I've given 50 points to your reputation as thanks!
Lifetime Member (joined September 2010) Likes (0)
Big Thanks! I really appreciate it =D
Become a member