MyBB Community Forums

Full Version: How to put php code in headers??
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

Can you help me to add php code and result be in <head></head>. I think it is easy to make it as plugin. The idea that I want the user change website and forum them by a click on theme and store theme no in cookies "not realated to user theme in db".
The part of saving theme in cookie is ok, but how to put this php in Mybb pages?

<style media="screen">
<?php 
$thm=$_COOKIE["thm"];
if ($thm<>""){
echo "@import url('themes/thm";
echo $thm;
echo ".css');";}
else{echo "@import url(themes/thm.css');";}
 ?></style>

Please note that this is not related to forum styles, I want disable forum styles and use above method, forum teplates doesn't allow adding php codes directly.
So... any idea please Wink
I know there is a plug in that allows php in templates.
Thanks for reply, I read adding php in templates effect on perfomance,

If I want to make a plugin, how to put something between <head></head> outout page.

For example in hello.php plugin
.
.
.
$plugins->add_hook("pre_output_page", "hello_world");
$plugins->add_hook("postbit", "hello_world_postbit");

function hello_world($page){
$page = str_replace("<div id=\"content\">", "<div id=\"content\"><p>Hello World!<br />This is a sample MyBB Plugin (which can be disabled!) that displays this message on all pages.</p>", $page);
return $page;
}

function hello_world_postbit($post){
$post['message'] = "<strong>Hello world!</strong><br /><br />{$post['message']}";
}

What hook can modify headers ??? this way if implemented is better than adding php to templates .

Regards,
I think you would need to put a variable in the template like {my_variable} and then populate that variable in your plug in using the global_start hook.

http://wiki.mybboard.net/index.php/MyBB_Plugin_Hooks
Thanks "skywalker2208" for these hooks, I will try.