How to inject CSS prior to the CSS4K2 system
First of all, what is CSS4K2? It injects a CSS file from your K2 theme so that you can have individual styles for each of your K2 themes. You can find the plugin here:
http://k2joom.com/k2-extensions/css4k2-extension
Its a pretty simple plugin and it works really well.
An Issue I found with CSS4K2
The problem with CSS4K2 plugin for K2 is that it inserts the CSS into the system earlier than the template’s addStyleSheet method in Joomla. I played around with the plugin load order, but somehow managed not to solve it in this way.
So what did I do? I flipped the stylesheet array from the Joomla Head. Here’s how you can do this:
//Below resets the css array. //first lets get the template url $template = JURI::base()."templates/".$this->template; $head_data = $this->getHeadData(); $orig_css = $head_data['styleSheets']; $mime = array('mime'=>'text/css'); reset($head_data['styleSheets']); $head_data['styleSheets'] = array_merge( array($template.'/css/bootstrap.min.css'=>$mime), array($template.'/css/bootstrap-responsive.min.css'=>$mime), array($template.'/css/style.css'=>$mime), $orig_css ); $this->setHeadData($head_data);"
Its a bit messy. It saves the original CSS header as $orig_css. It adds the original css at the end of the new array with your stylesheets. Then saves the data back into the Joomla head. This tutorial is handy especially if you’re using JCH optimizer. Check out our tutorial on JCH optimizer here.
Note: If you are not a developer I suggest you don’t try this at home.