Add metatags to all pages

walden systems, geeks corner, programming, languages, developer, mediawiki, customize, metatags
MediaWiki is a free and open source software wiki package written in PHP, originally for use on Wikipedia. It is now also used by several other projects of the non-profit Wikimedia Foundation and by many other wikis, including this website, the home of MediaWiki.

Sometimes you might need to add meta tags to every page in your MediaWiki site. There are many ways to accomplish this task and I would like to discuss one of the ways we are using here at Walden Systems, because we believe this is the most straightforward method to add meta tags to every page in your MediaWiki site.

Strategy to add meta tags to MediaWiki is fairly simple: First, you need to find the LocalSettings.php for your MediaWiki site. Second, we need create a function that renders the meta tags to all pages. Third, we need to include the function to be called.

Here are actual code samples:

The first thing you need to do is find the LocalSettings.php for your MediaWiki site. Once you do that we need to create a method to use the OutputPage object to write the meta tags to all pages:

1 function onOutputPageParserOutput( OutputPage &$out, ParserOutput $parseroutput ) 
2 {
3         $out->addMeta( 'keyword', 'some_keyword, some_keyword2, ...' );
4         return true;
5 }

Then you need to include the function so it gets called.

  $wgHooks['OutputPageParserOutput'][] = 'onOutputPageParserOutput';


So, this is how a final code for adding meta tags to MediaWiki site will look like:

1 $wgHooks['OutputPageParserOutput'][] = 'onOutputPageParserOutput';
2 
3 function onOutputPageParserOutput( OutputPage &$out, ParserOutput $parseroutput ) 
4 {
5         $out->addMeta( 'keyword', 'some_keyword, some_keyword2, ...' );
6         return true;
7 }