Extension:MetaDescriptionTag

An extension which gives users the ability to inject a &lt;meta&gt; description into the document header.

Note: Jim R. Wilson's excellent article Doing more with MediaWiki parser extensions contains a lengthy discussion of how this extension works.

The code on this page was updated for MediaWiki 1.16+. Another version, updated for 1.18 by Choshi, is available at this revision of this page. The differences appear to be minor.

Installation

 * 1) Create files named MetaDescriptionTag.php and MetaDescriptionTag.i18n.php, containing the code below, respectively.
 * 2) Copy these files to $IP/extensions/MetaDescriptionTag/.
 * Note: $IP is your MediaWiki install directory.
 * 1) Enable the extension by adding this line to your LocalSettings.php:

Usage
Once installed, editors of your wiki can add a &lt;meta&gt; description tag by adding the following to the article text: &lt;metadesc&gt; PageDescription &lt;/metadesc&gt; Where PageDescription would be replaced by the desired meta description.

For example, the above would become: &lt;meta name="description" content="PageDescription" /&gt;

Example using template, variable substitution
(This approach requires MediaWiki 1.12 - or install Extension:TagParser. Explanation at Manual:Tag_extensions.)

Say for example you want use a template to set the meta description to something like:

Extract from the article ARTICLETITLE

Create a template called (for example) "Template:Metadesc". Add the following content:

In the article to which you set the meta description, add: