Open main menu

Manual:Hooks/BeforePageDisplay

< Manual:Hooks
BeforePageDisplay
Available from version 1.7.0 (r14420)
Allows last minute changes to the output page, e.g. adding of CSS or JavaScript by extensions.
Define function:
public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) { ... }
Attach hook:

In extension.json:

{
	"Hooks": {
		"BeforePageDisplay": "MyExtensionHooks::onBeforePageDisplay"
	}
}

For MediaWiki ≤1.25:

$wgHooks['BeforePageDisplay'][] = 'MyExtensionHooks::onBeforePageDisplay';
Called from:File(s): OutputPage.php
Function(s): output

For more information about attaching hooks, see Manual:Hooks.
For examples of extensions using this hook, see Category:BeforePageDisplay extensions.

DetailsEdit

  • This hook was in SkinTemplate.php until version 1.12.0
  • $out - The OutputPage object.
  • $skin - Skin object that will be used to generate the page, added in 1.13.

UsageEdit

Scripts, styles, and other header elements can be added to the OutputObject at this point.

  • $out->addMeta( $name, $value ) - Add a <meta> tag.
  • $out->addKeyword( $text ) - Add a keyword for the keyword <meta> tag.
MediaWiki version: 1.17

For adding scripts and styles on MediaWiki 1.17 and above, use ResourceLoader modules.

  • $out->addModules( [ /*modules*/ ] ) - For modules with both scripts and styles
  • $out->addModuleStyles( [ /*modules*/ ] ) - For modules with styles only

See alsoEdit