okolobaxa
okolobaxa

Reputation: 342

Mediawiki: add script to page head in special namespace

Via this code I can add external script to page header on every page.

$wgHooks['BeforePageDisplay'][] ='onBeforePageDisplay';

function onBeforePageDisplay( OutputPage &$out, Skin &$skin )
{
  $script = '<script type="text/javascript" async src="https://relap.io/api/v6/head.js?token=<token>"></script>';
  $out->addHeadItem("Relap.io script", $script);

  return true;
};

How can I do same not in all namespaces?

Upvotes: 1

Views: 79

Answers (1)

Tgr
Tgr

Reputation: 28160

You can check the namespace via $out->getTitle()->getNamespace().

Upvotes: 1

Related Questions