MyBB Community Forums

Full Version: Including CSS style definitions from within a plugin
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

Am new to MyBB. Am trying to create a plugin. The thing that am having doubt now is how to include some css styles(10 lines max) in the header or anywhere in the page, without the admin to manually edit any template files?

I saw that there are several hooks available. But am having which one to be used as there's no description in that list!

Highly appreciate any suggestions or ideas.

Thank you
If I were you, I'd have your plugin modify the header_include template on activation. Note that this template is included on all pages. If you want, you could even reference an external style sheet (could even point to a PHP file to dynamically create the CSS).
You can install css files of a plugin on this way:
// add css file of plugin
	$css_array = array(
	"name" => "cssname.css", // name of css file - ends with .css
	"tid" => 1, 
	"attachedto" => "", // script name the css should be attached to (splitted by | ) - empty for all sites
	"stylesheet" => "", // stylesheet definitions
	"cachefile" => $db->escape_string(str_replace('/', '', cssname.css)),
	"lastmodified" => TIME_NOW
	require_once MYBB_ADMIN_DIR."inc/functions_themes.php";
	$sid = $db->insert_query("themestylesheets", $css_array);
	$db->update_query("themestylesheets", array("cachefile" => "css.php?stylesheet=".$sid), "sid = '".$sid."'", 1);
	$tids = $db->simple_select("themes", "tid");
	while($theme = $db->fetch_array($tids))

// remove added css file of plugin
	$db->delete_query("themestylesheets", "name = 'cssname.css'");

	require_once MYBB_ADMIN_DIR."inc/functions_themes.php";
	$query = $db->simple_select("themes", "tid");
	while($theme = $db->fetch_array($query))
Thanks you very much for the response.

Can you guide me what should be done if I wanted to inject JS ? I mean some jQuery code I wished to be included.
There is more than one way to include JS with a plugin. You could make it directly on this way: