You can dynamically change a page's meta tags from a plugin by including a function for the header_meta hook.
Here are two real examples. The first is from the Submit plugin which uses a post's content for the description tag. The second is from the Tags plugin which uses a post's tags as meta keywords.
PHP Code:/**
* Match meta tag to a post's description (keywords is done in the Tags plugin)
*/
public function header_meta($h)
{
if ($h->pageType == 'post') {
echo '<meta name="description" content="' . $h->post->content . '">' . "\n";
return true;
}
}
PHP Code:/**
* Match meta tag to a post's keywords (description is done in the SB Base plugin)
*/
public function header_meta($h)
{
if ($h->pageType != 'post') { return false; }
$meta_content = sanitize($h->post->content, 'all');
$meta_content = truncate($meta_content, 200);
echo '<meta name="description" content="' . $meta_content . '" />' . "\n";
return true;
}


Reply With Quote

Bookmarks