MetaTag

<< | Cookbook-V1 | >>

Note: The recipes here are for PmWiki versions 0.6 and 1.0 only. For PmWiki 2.0 recipes, see Cookbook.


Goal

Adding page related meta tags to a page

  • Meta-tags with keywords,descriptions etc.
  • Usage of the http-equiv tag to redirect to a page outside the wiki.

Solution

Site (and group metatags)

This can be solved with something like the code in the following box:

Added to local.php or group.php

  $HTMLTitleFmt = array (
      "<title>\$HTMLTitle \$Title</title>",
      "<meta http-equiv=\"Content-Language\" content=\"nl\">",
      "<META name=\"revisit-after\" content=\"30\">",
    ); 

How to keep robots away.

=note Note: PmWiki version 0.6 already has built-in features for controlling robots. See the scripts/stdconfig.php file and the $MetaRobots variable.

The robots page describes the usage of the robots.txt file to control web-robots. However the used wildcards in the examples are not defined by the robots exclusion definition. Allthought it works for most robots. Following is an example on using metatags to control robots:

Added to local.php or group.php

  if($action and $action!='browse')
     $robots="noindex,nofollow";
  else
     $robots="index,follow";
  array_push($HTMLTitleFmt,"<META CONTENT=\"$robots\" NAME=\"robots\">");

Per page metatags

The attached code is an addition to add meta tags to single pages

Attach:metatag-1.10.php

Installation

  • Save the code above in your local directory.
  • Add include_once("local/metatag.php"); to the end of your local.php

Usage

Add the tag:

  content-text? 

between your page text, doesn't matter where in the text, it will translate to:

  <META name="name" content="content-text">

Add the tag:

  <time>? 

between your page text, doesn't matter where in the text. The 'where' must be defined in your metatag.php, this to avoid nasty redirects (consider a page named ForKids and a redirect to www.nastypictures.com) Time is set to 1 when omitted. It will translate to:

  <META http-equiv="refresh" content="time;url=translated_where">

Examples

It solves most robot related meta tags:

 index,follow?
 2?
 blue widgets?
 Some information about blue widgets?

 5?

results in:

 <META name="robots" content="index,follow">
 <META name="revisit-after" content="2">
 <META name="keywords" content="blue widgets">
 <META name="description" content="Some information about blue widgets">

 <META http-equiv="refresh" content="5;url=[(approve links)
  edit
  diff]">

History

23-11-2003 Initial try.
24-11-2003 Added http-equiv
05-12-2003 Added nicer array_push to code
09-01-2004 Added text about robot tags
10-01-20041.9Changed the 'equiv' tag to 'refresh', and the items for 'refresh' must be predefined.
26-01-20041.10Ensure HTMLTitleFmt is an array

Comments, Bugs

I get the following errors with this plugin:

Warning: array_push(): First argument should be an array in /home/grainof/public_html/local/metatag.php on line 81

Thanks, Oneida Kincaid 01/25/2004

solved in version 1.10

Thanks for the quick fix, it works like a charm now! Thanks for a great plugin. Oneida


This plugin works like a charm with PmWiki 1.0.5 in terms of giving you per-page keyword and description metatags if you put <!--function:PrintMetaTags--> in the header section of your template. It took me a little while to figure that out, so I thought I mention it for those who would like to use it with more recent versions of PmWiki.

Oneida Kincaid 07/26/2004


Just thought I'd add a link from here to PmWiki/MarkupMasterIndex since I wasted a bunch of time trying to use this recipe to do metatags in v2 before I found the proper directive on that page...

shi September 04, 2005, at 11:30 PM


Contributors

--- pmwiki-2.3.38 -- Last modified by {{shi}}

from IP: 85.171.160.186 ip should be disabled by default for security reasons