Open main menu

Manual:Hooks/ParserBeforeTidy

ParserBeforeTidy
Available from version 1.5.0
Used to process the nearly-rendered HTML code for the page (but before any HTML-tidying occurs)
Define function:
public static function onParserBeforeTidy( Parser &$parser, string &$text ) { ... }
Attach hook:

In extension.json:

{
	"Hooks": {
		"ParserBeforeTidy": "MyExtensionHooks::onParserBeforeTidy"
	}
}

For MediaWiki ≤1.25:

$wgHooks['ParserBeforeTidy'][] = 'MyExtensionHooks::onParserBeforeTidy';
Called from:File(s): parser/Parser.php
Function(s): internalParseHalfParsed

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

DetailsEdit

This hook allows to intercept processing after all HTML has been generated but before it has been standardized (via Tidy).

  • $parser: Parser object
  • &$text: Actual text as a string

ExampleEdit

$text will hold the text for the page. To change the page text, modify this value. E.g. to add the phrase "The mighty oracle gives forth this proclamation: " to the front of the page text, you would use the following code:

$text = "The mighty oracle gives forth this proclamation: " . $text;

See alsoEdit