WordPress: Using post tags as META tag in HTML and displaying in Window title bar

To make your wordpress blog easily searchable by search engines like Google, Yahoo, Bing – you can do a small hack to your theme’s header.php file.

Technique -1: Adding tags in Browser window title bar:

In most of the themes, this file displays Page title and Blog name in browser window title bar while a user is browsing single page or post. We can very well add the tags associated with that post with the following simple technique.

The below code snippet gets the list of tags associated with the post/page and displays it.

<?php $alltags = strip_tags(get_the_tag_list(”,’, ‘,”));
echo $alltags; ?>

Include the above code in is_single() || is_page() block in your theme’s header.php. For me it looks like the below one.

<?php } else if (is_single() || is_page()) { ?>
<?php wp_title(”); ?><?php $alltags = strip_tags(get_the_tag_list(”,’, ‘,”));
echo $alltags; ?> – <?php bloginfo(‘name’); ?>
<?php } else if (is_archive()) { ?>
Technique-2: Adding tags as keyword META tag for search engine to identify it easily:
Add the following META tag in your header.php file, between <HEAD> and </HEAD>. This will dynamically generate tags of a post and use it as keywords for that post.

<META name=”keywords” content=”<?php $alltags = strip_tags(get_the_tag_list(”,’, ‘,”));
echo $alltags; ?>”>

Here is the sample of a post displaying its tags in browser window title bar.

Displaying Tags on Browser window title bar (click to enlarge)
Share this post

One comment

Leave a Reply to eswar Cancel reply

Your email address will not be published. Required fields are marked *