• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WPArena

WPArena

WPArena is a premium online resource site of WordPress and is focused on providing excellent WordPress Tutorials, Guides, Tips, and Collections.

  • News
    • Opinion
  • Tutorials
  • Reviews
    • Themes
    • Plugins
  • Comparisons
  • Collections
    • Education Themes
    • Genesis Child Themes
    • Best Responsive Themes
    • Medical WordPress Themes
    • Finance & Business Themes
    • Crowdfunding Themes
  • Resources
    • Inspiration
  • Services
WPArena » Tutorials
Tutorials

How to use Categories and Tags as Keywords

Avatar of Noor Mustafa Raza Noor Mustafa Raza Updated: June 19, 2022

Categories and Tags as Keywords
FacebookTweetPinLinkedInEmailPrint

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.

 

This post was orginally published on: November 10, 2010 and was updated on: June 19, 2022.
FacebookTweetPinLinkedInEmailPrint

Related Stories

  • How To Setup Flash Slideshow On WordPress Theme Header

    How To Setup Flash Slideshow On WordPress Theme Header

  • 5 Simple Steps To Make Money As A Blogger

  • How To Convert A Static HTML Page in to A WordPress Page

    How To Convert A Static HTML Page in to A WordPress Page

Avatar of Noor Mustafa Raza

Noor Mustafa Raza

Ex-Editor in chief

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.

Reader Interactions

Join the Discussion
  1. Avatar of Joe @AppsarabyJoe @Appsaraby says

    November 25, 2018

    Thank you a lot for the code
    Will it work with third-party plugins like Woocommerce and products?

    Reply
  2. Avatar of JCPJCP says

    January 16, 2020

    Thumbs up for really simple and cool solution!!!

    Reply

Share Your Thoughts Cancel reply

Before submitting your comment, we kindly ask that you read our comment policy. Your email address will remain confidential and will not be published or shared anywhere. If you subscribe, you will receive notifications regarding new comments.

Primary Sidebar

WordPress development tutorial channels in Youtube

Top WordPress Development Tutorial Channels on Youtube

WordPress Version Updates

Outstanding New features of WordPress 3.1 (Reinhardt)

Recent Topics

  • 27 Top SEO Companies in the World
  • 12 Ways To Monetize Your WordPress Blog
  • Comparing the Best Employee Engagement Software in the Market
  • Stellar Converter for OST Review: Best Tool for OST to PST Conversion
  • How To Use WordPress as an eCommerce Store

Footer

Top

  • Services
  • Our Themes
  • Facebook
  • Twitter
  • Linkedin

Reviews

  • Beaver Builder Review
  • Beaver Themer Review
  • WP User Frontend Pro
  • Ninja Forms Review
  • MemberPress Review

More Reviews »

Resources

  • Best WordPress Plugins
  • WordPress Permalinks Structure
  • Email Management System
  • Envato Free Files
  • Advertise
  • Write for us
  • Disclosure
  • Terms
  • Privacy
  • Contact

Copyright © 2023 · All Rights Reserved · WPArena is a Project of TechAbout LLC.
We are not affiliated with Automattic or WordPress.

  • Advertise
  • Write for us
  • Disclosure
  • Terms
  • Privacy
  • Contact
Share this ArticleLike this article? Email it to a friend!

Email sent!