Jump to content

Extension:HeaderExtension

From mediawiki.org
This page is a translated version of the page Extension:HeaderExtension and the translation is 30% complete.
MediaWiki 拡張機能マニュアル
HeaderExtension
リリースの状態: 安定
実装 フック , 自分のウィキ
説明 Adds Scripts and Meta data just before the ‎</head> tag of the wiki
作者
最新バージョン 3.1.0 (2026-04-22)
互換性の方針 master が後方互換性を維持しています。
MediaWiki 1.35+
PHP 7.3.19+
データベースの変更 いいえ

  • $wgHeaderHeadItems
  • $wgHeaderMetaItems
ライセンス MIT ライセンス
ダウンロード
README
CHANGELOG

The HeaderExtension extension allows Scripts and Meta data to easily be added just before the ‎</head> tag of the wiki.

The code for the head Scripts and Meta data are defined in "LocalSettings.php " and is controlled by variables. This implementation makes it easy for inexperienced users to implement head Scripts and Meta data just before the ‎</head> tag of the wiki. It also makes it possible to add head Scripts and Meta data that cannot be changed or removed, such as would be possible by wiki 管理者 if the head Scripts and Meta data were added to the Sitenotice . 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.

インストール

  • ダウンロードして、ファイルをextensions/フォルダー内のHeaderExtensionという名前のディレクトリ内に配置します。
  • 以下のコードを LocalSettings.php ファイルの末尾に追加します:
    wfLoadExtension( 'HeaderExtension' );
    
  • 必要に応じて設定します。
  • Yes 完了 – ウィキの「Special:Version」に移動して、拡張機能が正しくインストールされたことを確認します。

設定

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

スクリプト

Scheme

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

(Since Version 3.1)

$wgHeaderHeadItems = [
    '<script>Script example 1 here</script>',
    '<script>Script example 2 here</script>'
];

Leave untouched the first and last line with START_END_MARKER stuff, this is a special syntax of PHP (without it, it would be tricky to deal with apostrophes inside the script). Do not add whitespaces around the last line’s marker, it would break it (more details about this syntax). Do add new line after.

Examples:

$_GoogleAnalyticsId = 'your_code';
$wgHeaderHeadItems = [
        '<script async src="https://www.googletagmanager.com/gtag/js?id=' . $_GoogleAnalyticsId . '"></script>',
        '<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag("js", new Date());
 
  gtag("config", "' . $_GoogleAnalyticsId . '");
</script>',
        '<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=' . $_GoogleAnalyticsId . '" height="0" width="0" style="display:none;visibility:hidden"></iframe>'
    ];
$wgHeaderHeadItems = [
    '<meta name="robots" content="noarchive" />'
];

Meta data

Scheme

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

(Since Version 3.1)

$wgHeaderMetaItems[ 'meta_key_1' ] = 'Meta example 1 here';
$wgHeaderMetaItems[ 'meta_key_2' ] = 'Meta example 2 here';

$wgHeaderMetaItems = [
    [ 'age-de-meta-label', 'age=0 hash: yourdigitalcode v=1.0 kind=sl protocol=all' ],
    [ 'robots', 'noarchive' ]
];

関連項目

The extension HeaderExtension combines functionality from