Hotaru Docs

 [həʊdɒks]

Changing the Meta Tags

You can dynamically change a page's meta tags from a plugin by including a function for the header_meta hook.

If you just want to change the wording, you can edit the language files, e.g. main_language.php, tags_language.php and users_language.php.

Here are two real examples. The first is from the SB Base 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.

/**
 * Match meta tag to a post's description (keywords is done in the Tags 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;
}
/**
 * Match meta tag to a post's keywords (description is done in the Submit plugin)
 * Also changes meta when browsing a tag page
 */
public function header_meta($h)
{    
    if ($h->pageType == 'post')
    {
        echo '<meta name="keywords" content="' . stripslashes($h->post->tags) . '" />' . "\n";
        return true;
    } 
    elseif ($h->subPage == 'tags')
    { 
        $tag = stripslashes($h->vars['tag']); 
 
        if ($tag) {
            echo '<meta name="description" content="' . $h->lang['tags_meta_description_before'] . $tag . $h->lang['tags_meta_description_after'] . '" />' . "\n";
            echo '<meta name="keywords" content="' . $tag . $h->lang['tags_meta_keywords_more'] . '" />' . "\n";
            return true;
        }
    }
}
Getting StartedDesign and LayoutPlugin DevelopmentAdvanced TopicsFunction ReferenceTroubleshooting