How to use Categories and Tags as Keywords

Categories and Tags as Keywords

A tag, or keyword, is a word or phrase that’s descriptive and specific to your article or web page. The right keywords will help optimize your exposure and also your positioning in search engines, which is where many people may find your article.

Adding meta keywords to your single post archive template gives you all the data you need. your categories and tags. All you have to do is get a combined list, separated by commas. You first use a conditional tag to make sure this code is used only on single post archives.

(Pages don’t have categories or tags, and the get_the_tags() and get_the_category() functions won’t work correctly on archive pages containing multiple posts.) Then, for each tag and category, you force the name to all lowercase and add it to an array of keywords. As you print the <meta> tag, you remove duplicates from the array with array_unique() and convert the array to a comma-separated string using implode().

In the following lines of code, you will learn how to build the array of keywords and print it as the content of the <meta> tag.

Use Categories and Tags as Keywords

Here is a simple snippet for Creating meta keywords tags from post categories and tags in header.php.

<?php if (is_single()) {
foreach((get_the_tags()) as $tag) {
$keywords[] = strtolower($tag->name);
foreach((get_the_category()) as $category) {
$keywords[] = strtolower($category->cat_name);
<meta name="keywords" content="<?php echo implode(", ", array_unique($keywords)); ?>" />
<?php } ?>

Making these changes in your theme’s header file will help improve search engine optimization. All in One SEO Pack- WordPress  Plugin will help you to write good tags and you can easily implement them on your WordPress-powered site. You can find details on how to improve WordPress title tags.


Leave a Reply

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

Sign Up for Our Newsletters

Get notified of the best deals on our WordPress themes.

You May Also Like