This is an old revision of the document!
Table of Contents
HtmlMetaTags Plugin
Compatible with DokuWiki
2012-10-13 "Adora Belle",2013-05-10a "Weatherwax",Release 2013-12-08 "Binky",Release 2014-05-05e "Ponder Stibbons",Release 2014-09-29d "Hrun", 2015-08-10 "Detritus"
This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.
Similar to meta, socialcards
Description
This plugin enriches the html page with all meta tags what you wont, e.g. keywords, description and any others. Some meta information are very usefull for web crawlers for indexing and categorizing the page.
Syntax
With the string {{htmlmetatags>...}}
on the page level you activates the plugin. The leading string “metatag-” marks a tag for the web site. After this leading string followed the key from tag. In :(...)
write the value of the tag.
Also, the plugin is on page level.
Example to activate the plugin on your page write:
{{htmlmetatags>metatag-mytag:(some usefull text)}}
The meta tag: mytag is any word. This word is the name of the new meta tag, e.g. keyword. Followed on this name is to write :
with ('...')
. This brackets contains the text required for the value of the new meta tag.
You can write more than once meta tag on the page separate by space.
{{htmlmetatags>metatag-robots:() metatag-keywords:(apfel,bananne,birne) metatag-description:(Allgemeiner Obstbauer)}}
The result on web page is:
<meta name="robots" content=""/> <meta name="keywords" content="apfel,bananne,birne"/> <meta name="description" content="Allgemeiner Obstbauer."/>
Installation
Download the plugin at htmlmetatags.zip and extract the zip file to the plugin folder on your dokuwiki.
Change Log
- 2015-05-27 Initial release
- 2016-04-22 Change the date for “last Update”
FAQ
Discussion
The date in plugin.info.txt is not correct! Maybe a typo, but dw says “update available”.
Improve completeness of accepted metatags
This code allow you to add :
- open graph metatags like og:description, og:image…
- link to media file. tags must start with media-
- media-og:image=(:wiki:image.jpg)
- multiple calls to htmlmetatags all values will be added
Syntax is improved to (note the difference of attribute to value splitter from : to
{{htmlmetatags>metatag-keywords=(values) metatag-og:description=(open graph description.)}}
Note: you can add linebreaks inside the {{ }} without any trouble.
{{htmlmetatags>metatag-keywords=(values) metatag-og:description=(open graph description.) }}
To implement this, replace these two functions in syntax.php with the following code.
/** * Based on the code by Heiko Heinz * Modifications by Eric Maeker, 2016, BSD licence */ /** * Handle matches of the htmlmetatags syntax * * @param string $match The match of the syntax * @param int $state The state of the handler * @param int $pos The position in the document * @param Doku_Handler $handler The handler * @return array Data for the renderer */ public function handle($match, $state, $pos, Doku_Handler &$handler){ // Remove all linefeeds before parsing attributes $match = str_replace(PHP_EOL,"",$match); // Explode match into attributes array using 'metatag-' as mask return explode("metatag-", preg_replace("/{{htmlmetatags>(.*?)}}/","\\1", $match)); } /** * Render xhtml output or metadata * * usage: {{htmlmetatags>metatag-keywords:(apfel,bananne,birne) metatag-description:(Allgemeiner Obstbauer)}} * @param string $mode Renderer mode (supported modes: xhtml) * @param Doku_Renderer $renderer The renderer * @param array $data The data from the handler() function * @return bool If rendering was successful. */ public function render($mode, Doku_Renderer &$renderer, $data) { global $ID; switch ($mode) { case 'metadata' : /* * e.g. * data[0]="keywords=(apfel, bananne, birne) " * data[1]="og:description=Allgemeiner Obstbauer" */ for ($i=0;$i<sizeof($data);$i++) { $mt = explode("=", $data[$i]); $size = sizeof($mt); // If attributes as value if(sizeof($mt)==2){ $name = trim($mt[0]); $content = trim(preg_replace("/\((.*?)\)\s*$/","\\1",$mt[1])); // Test if attribute name is a media files and get media file absolute URL if (substr($name, 0, 6) === 'media-') { $name = substr($name, 6); $content = ml($content, '', true, '&', true); } // Send result to renderer if (!empty($content)) $renderer->meta["htmlmetatags"][$name] .= $content; } } return true; } return false; }