Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
How to insert a .js file to header?
How to insert a .js file to header?
or i want to insert some js code to header, how to do that?
or i want to insert some js code to header, how to do that?
Tagged:
0
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.
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.
http://www.vanillaforums.org/addon/608/analytics
such as i want to add a simply navigation bar under the vanilla's header.
thx again, you are a nice guy :-)
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() {} }
What you want to do is create a theme. Take a look at http://www.vanillaforums.org/page/ThemeQuickStart for some help with that.
I just want to add :
<!--[if lte IE 8]> <link type="text/css" rel="stylesheet" href="styles-ie.css" /> <![endif]-->
Any ideas ?
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.
It works! Thanks you very much
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. :-)
{literal}
the code
{/literal}