How to use 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.

 

Disclosure: Some of the links in this article are affiliate links and we may earn a small commission if you make a purchase, which helps us to keep delivering quality content to you. Here is our disclosure policy.

Noor Mustafa Raza
Noor Mustafa Raza
I am a WordPress Developer and Designer, author @WPArena. I am providing Free WordPress consultation and can help you to install WordPress in a secure way to small businesses and bloggers.

2 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here
Captcha verification failed!
CAPTCHA user score failed. Please contact us!

spot_img

Related Articles

How to Reduce WordPress Registration Spam

WordPress forms offer a valuable chance for you to connect with your website visitors and potential customers. Those people may...
Read More
Why WordPress is the best CMS? Having a website has become a necessity for both individuals and businesses. Content Management...
When optimizing the speed of your WordPress site, you might come across a performance metric known as Time to First...