Make a folder inside your plugins folder. Inside that new folder, make a file called default.php and put this in it: <?php if (!defined('APPLICATION')) die();
class InsertSomeJS extends Gdn_Plugin { public function Base_Render_Before(&$Sender) { $Sender->AddJsFile($this->GetResource('myJSfile.js', FALSE, FALSE)); }
public function Setup() {} }
Now create myJSfile.js in the same directory and it will be added to the page head. Edit to your liking of course.
but it is the only way to insert js or other code? If i just insert some script code, such as google analytics code, how to do that? I don't want to use the plugin because it use the old analytics code.
thx, but i still want to know how to add script code or other code in header if it's not a analytics code? such as i want to add a simply navigation bar under the vanilla's header.
//This isn't what you want, but i'll leave it here in case someone wants to know how to add inline javascript.
Do the same as above, but use this as default.php instead:<?php if (!defined('APPLICATION')) die();
$PluginInfo['InlineScript'] = array ( 'Name' => 'InlineScript', 'Description' => 'Adds script to head of all pages', 'Version' => '0.1', 'Author' => 'Your name', 'AuthorEmail' => 'your@email.com', 'AuthorUrl' => 'http://example.com' );
class InlineScript extends Gdn_Plugin { public function Base_Render_Before(&$Sender) { $Sender->Head->AddString ( "<script type=\"text/javascript\">// your script goes here</script>" ); }
You should make a folder in your forum root called plugins/InlineScript.
This folder should contain a file called default.php.
That file should contain the code in this comment.
You see where it says $Sender->Head->AddString ? You need to replace what is inside the "" with the code you want to add. $Sender->Head->AddString("<!--[if lte IE 8]>\n<link type=\"text/css\" rel=\"stylesheet\" href=\"styles-ie.css\" />\n<![endif]-->"); You will need to go to your dashboard and enable the InlineScript plugin.
Comments
<?php if (!defined('APPLICATION')) die();
$PluginInfo['InsertSomeJS'] = array(
'Description' => 'Insert some JS',
'Version' => '0.1',
'Author' => 'Your Name',
'AuthorEmail' => 'your@email.com',
'AuthorUrl' => 'http://example.com'
);
class InsertSomeJS extends Gdn_Plugin
{
public function Base_Render_Before(&$Sender)
{
$Sender->AddJsFile($this->GetResource('myJSfile.js', FALSE, FALSE));
}
public function Setup() {}
}
Now create myJSfile.js in the same directory and it will be added to the page head.
Edit to your liking of course.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •but it is the only way to insert js or other code?
If i just insert some script code, such as google analytics code, how to do that?
I don't want to use the plugin because it use the old analytics code.
thx again, i am a green hand in vanilla.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •http://www.vanillaforums.org/addon/608/analytics
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •such as i want to add a simply navigation bar under the vanilla's header.
thx again, you are a nice guy :-)
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •Do the same as above, but use this as default.php instead:
<?php if (!defined('APPLICATION')) die();
$PluginInfo['InlineScript'] = array
(
'Name' => 'InlineScript',
'Description' => 'Adds script to head of all pages',
'Version' => '0.1',
'Author' => 'Your name',
'AuthorEmail' => 'your@email.com',
'AuthorUrl' => 'http://example.com'
);
class InlineScript extends Gdn_Plugin
{
public function Base_Render_Before(&$Sender)
{
$Sender->Head->AddString
(
"<script type=\"text/javascript\">// your script goes here</script>"
);
}
public function Setup() {}
}
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •What you want to do is create a theme. Take a look at http://www.vanillaforums.org/page/ThemeQuickStart for some help with that.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •I just want to add :
<!--[if lte IE 8]><link type="text/css" rel="stylesheet" href="styles-ie.css" />
<![endif]-->
Any ideas ?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •This folder should contain a file called default.php.
That file should contain the code in this comment.
You see where it says $Sender->Head->AddString ? You need to replace what is inside the "" with the code you want to add.
$Sender->Head->AddString("<!--[if lte IE 8]>\n<link type=\"text/css\" rel=\"stylesheet\" href=\"styles-ie.css\" />\n<![endif]-->");You will need to go to your dashboard and enable the InlineScript plugin.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •It works! Thanks you very much ;)
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •the insert js to header is working now.
but i still have a problems, if i want to insert a js file to footer, how to do it?
thx again. :-)
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •{literal}
the code
{/literal}
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •