Hi,
I'm trying to output some tags just before the </head> attribute on each page generated by MW.
Since I want to minimize updating headaches, I'm trying the extension way. But for the life of me, I can't find the right hook or syntax.
My Manual searches gave me the OutputPageBodyAttributes hook but it's 1.17 only.
Anyone got the right hook, or a simple syntax example?
Thanks a lot.
Use the BeforePageDisplay hook and $out->addHeadItem if there is no more specific method for what you're trying to insert (ie: a <link>, <meta>, <script>, <style>, etc...)
http://www.mediawiki.org/wiki/Manual:Hooks/BeforePageDisplay
~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://daniel.friesen.name]
On 11-04-30 05:39 AM, Dorem - Jérémie Bouillon wrote:
Hi,
I'm trying to output some tags just before the </head> attribute on each page generated by MW.
Since I want to minimize updating headaches, I'm trying the extension way. But for the life of me, I can't find the right hook or syntax.
My Manual searches gave me the OutputPageBodyAttributes hook but it's 1.17 only.
Anyone got the right hook, or a simple syntax example?
Thanks a lot.
On 30/04/2011 22:37, Daniel Friesen wrote:
Use the BeforePageDisplay hook and $out->addHeadItem if there is no more specific method for what you're trying to insert (ie: a<link>,<meta>,
<script>,<style>, etc...) http://www.mediawiki.org/wiki/Manual:Hooks/BeforePageDisplay
Just what I was looking for, thanks a lot.
Is there a way to control exactly where the content is added?
I used the $out->addScript way to add my script, but it's not placed at the end (there's the sshover.htc IE call and a vector script added after it).
Dorem - Jérémie Bouillon wrote:
On 30/04/2011 22:37, Daniel Friesen wrote:
Use the BeforePageDisplay hook and $out->addHeadItem if there is no more specific method for what you're trying to insert (ie: a<link>,<meta>,
<script>,<style>, etc...) http://www.mediawiki.org/wiki/Manual:Hooks/BeforePageDisplay
Just what I was looking for, thanks a lot.
Is there a way to control exactly where the content is added?
I used the $out->addScript way to add my script, but it's not placed at the end (there's the sshover.htc IE call and a vector script added after it).
Just out of curiousity, to avoid or perhaps solve a less-than-ideal construction, why does it have to be at the end per se ? What is it you want to insert there ?
-- Krinkle
On 01/05/2011 13:31, Krinkle wrote:
Just out of curiousity, to avoid or perhaps solve a less-than-ideal construction, why does it have to be at the end per se ? What is it you want to insert there ?
Two things. First, I'm starting to seriously use MW, so it helps me learning it :-)
Second in this specific case, it's for Google Analytics. Since they have changed it to a faster and asynchronous javascript handling, there's no extension with the appropriate code anymore, and they strongly advise to place it here (last thing before /head).
I'll adjust the code position in the future with more test and feedback when my site goes public, but right now I don't see the harm in following their recommendation, and perhaps more important to have the same result across the various part of my site (hence, having it placed on the same spot).
Dorem - Jérémie Bouillon wrote:
On 01/05/2011 13:31, Krinkle wrote:
Just out of curiousity, to avoid or perhaps solve a less-than-ideal construction, why does it have to be at the end per se ? What is it you want to insert there ?
Two things. First, I'm starting to seriously use MW, so it helps me learning it :-)
Second in this specific case, it's for Google Analytics. Since they have changed it to a faster and asynchronous javascript handling, there's no extension with the appropriate code anymore, and they strongly advise to place it here (last thing before /head).
I'll adjust the code position in the future with more test and feedback when my site goes public, but right now I don't see the harm in following their recommendation, and perhaps more important to have the same result across the various part of my site (hence, having it placed on the same spot).
Note that 1.17 introduces ResouceLoader for packing javasccript and css resources.
Dorem - Jérémie Bouillon wrote:
On 01/05/2011 13:31, Krinkle wrote:
Just out of curiousity, to avoid or perhaps solve a less-than-ideal construction, why does it have to be at the end per se ? What is it you want to insert there ?
Two things. First, I'm starting to seriously use MW, so it helps me learning it :-)
Second in this specific case, it's for Google Analytics. Since they have changed it to a faster and asynchronous javascript handling, there's no extension with the appropriate code anymore, and they strongly advise to place it here (last thing before /head).
I'll adjust the code position in the future with more test and feedback when my site goes public, but right now I don't see the harm in following their recommendation, and perhaps more important to have the same result across the various part of my site (hence, having it placed on the same spot).
The Google Analytics script doesn't rely on any other resources. The order/ /position of the script inside the <head> (or <body>) doesn't matter.
Google however likes to keep things simple for users to avoid complication. They recommend placing it right before </head>, that way everybody knows where it must go, even for users who have little to no clue about HTML and the Document Object Model.
I'm pretty sure it doesn't make any difference where you add it in your document as long as it's parsed by the browser.
If you look at other scripts from google they sometimes say "inside <head>", sometimes "at the end of <body>" or "right before </head>" or ".. </ body>".
It's just a way to simplify it for the users. It doesn't have to be at the very end of beginning of a tag, nor should it matter whether it's in <head> or <body>.
Add it somewhere and see if it works. If it does, you're doing it Right ;-)
-- Krinkle
mediawiki-l@lists.wikimedia.org