Extension:HeadScript

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.svg
HeadScript

Release status:Extension status stable

ImplementationTemplate:Extension#type Hook
DescriptionTemplate:Extension#description Adds scripts just before </head> of the wiki that are defined in LocalSettings.php
Author(s)Template:Extension#username (JinRyuuNagytalk)
Latest versionTemplate:Extension#version 1.0 (2015-08-06)
Database changesTemplate:Extension#needs-updatephp No
LicenseTemplate:Extension#license GNU General Public License 2.0
Download DOWNLOAD
README
ParametersTemplate:Extension#parameters
  • $wgHeadScriptName
  • $wgHeadScriptCode
Hooks usedTemplate:Extension#hook
BeforePageDisplayManual:Hooks/BeforePageDisplay

Translate the HeadScript extension if it is available at translatewiki.net

Check usage and version matrix.

The HeadScript extension allows scripts to easily be added just before </head> of the wiki. The code for the head script is defined in LocalSettings.php and is controlled by variables. This implementation makes it easy for inexperienced users of MediaWiki to implement head scripts just before </head> of the wiki. It also makes it possible to add head scripts that cannot be changed or removed, such as would be possible by wiki administrators if the head script were added to the site notice. This makes the extension particularly useful for placing Cookie Consent plugin or css style links, as such content cannot be removed by abusive or rogue administrators.

Installation[edit]

  • Download and extract and place the file(s) in a directory called HeadScript in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
    require_once "$IP/extensions/HeadScript/HeadScript.php";
    
  • Configure as required
  • YesY Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Configuration[edit]

One or more head scripts can be added to the wiki. The head scripts can consist of any HTML and/or JavaScript.

To configure the head script, add the following to LocalSettings.php after the installation line:

$wgHeadScriptCode = '
<script></script>
';

To add additional scripts, simply include them between the apostrophes:

$wgHeadScriptCode = '
<script></script>
<script></script>
<script></script>
';

You may specify a name for the script too if needed, add the following after the installation line:

$wgHeadScriptName = '
Your name of your script code here.
';