Add metatags to all pages
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 }