WordPress Meta Keywords by RankYa

WordPress Optimized for Search Ranking

Using WordPress popular SEO Plugins such as Yoast which seem to NOT use meta keywords tag anymore? Let’s fix that so that you too can continue using it (just because some SEO experts say that you shouldn’t doesn’t mean that you shouldn’t.).

Here you’ll fine some WordPress specific PHP codes you can insert in to your Theme template file so that your blog posts automatically insert meta keywords using Tags you tagged for the post you created.

Warning: make sure you backup (download) your current header.php before you modify that file. If for some reason something goes wrong, you can simply re-upload your backedup header.php file to the same location on your server.

Code that Generates Meta Keywords Tag

<?php global $wp_query; if ( is_single() ) : ?> <?php $posttags = get_the_tags(); ?> <?php if ($posttags) : ?> <?php $get_keys = array_keys($posttags); $last_key = array_pop($get_keys); ?> <meta name="keywords" content="<?php foreach($posttags as $key => $value) { $tag_name = $value->name; if($key == $last_key) { echo $tag_name; } else { echo $tag_name.', '; } } ?>"> <meta itemprop="keywords" content="<?php foreach($posttags as $key => $value) { $tag_name = $value->name; if($key == $last_key) { echo $tag_name; } else { echo $tag_name.', '; } } ?>"> <?php else: ?> <!--do nothing for if NO posttags--> <?php endif; ?> <?php endif; ?>

How to Use It? The Process

Simply place this code in header.php file of your WordPress theme, make sure it is placed within <head>anywhere within head portion</head>

Where is that file?

Login to Web Hosting Account > file manager > public_html > wp-content > themes > YourThemeName > header.php file

Warning: make sure you backup (download) your current header.php before you modify that file. If for some reason something goes wrong, you can simply re-upload your backedup header.php file to the same location on your server.

Meta Keywords for WooCommerce

<?php global $wp_query; if ( is_single() && !is_product() && !is_front_page() && !is_home() && !is_page() && !is_paged() && !is_archive() && !is_category() && !is_feed() && !is_attachment() && !is_404() ) : ?> <?php $posttags = get_the_tags(); ?> <?php if ($posttags) : ?> <?php $get_keys = array_keys($posttags); $last_key = array_pop($get_keys); ?> <meta name="keywords" content="<?php foreach($posttags as $key => $value) { $tag_name = $value->name; if($key == $last_key) { echo $tag_name; } else { echo $tag_name.', '; } } ?>"> <meta itemprop="keywords" content="<?php foreach($posttags as $key => $value) { $tag_name = $value->name; if($key == $last_key) { echo $tag_name; } else { echo $tag_name.', '; } } ?>"> <?php endif; ?> <?php elseif ( is_product() ): ?> <?php $terms = get_the_terms( $post->ID, 'product_tag' ); ?> <?php if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) : ?> <?php $get_keys = array_keys($terms); $last_key = array_pop($get_keys); $rankyacheck = array(); ?> <meta name="keywords" content="<?php foreach ( $terms as $term => $value) { $rankyacheck = $value->slug; if($term == $last_key) { echo $rankyacheck; } else { echo $rankyacheck.', '; } } ?>"> <meta itemprop="keywords" content="<?php foreach ( $terms as $term => $value) { $rankyacheck = $value->slug; if($term == $last_key) { echo $rankyacheck; } else { echo $rankyacheck.', '; } } ?>"> <?php endif; ?> <?php else: ?> <!--do nothing for if NO posttags--> <?php endif; ?>

How to Use It?

Same Process as mentioned above.

What Does the WooCommerce Version Do?

It does the same thing for blog posts, it generates meta keywords automatically pulling in post tags, furthermore, it also pulls Product Tags for WooCommerce product and generates that automatically as well. How great is that? That’s the benefits of learning with RankYa.

Yoast Meta Keywords Missing?

Popular Search Engine Optimization plugins such as Yoast SEO Plugin have decided to disable meta keywords tag, but you can now use RankYa custom WordPress codes to generate meta keywords tag automatically.

Want to get a hold of more WordPress SEO codes like this? Simply subscribe to RankYa mailing list

Don't let Google's latest Page Experience update derank your business website in search, instead, master Google rankings and website conversions with this Master Class Course by RankYa (Free Lessons Included)

Learn how press here

By RankYa

RankYa is a passionate digital marketer, website optimizer, content creator, and a fully qualified web developer helping businesses of all sizes (big or small) to achieve better results online. We are a reputable and registered Australian business serving valued clients worldwide since 2008, built on hard work, honesty and providing exceptional personalized service

We love sharing our passion through freely available how to videos and courses related to business website marketing and optimization, Google (Search Console, Ads, Analytics, YouTube), SEO, HTML5, Structured Data and WordPress. Thank you for visiting our website. Rest assured that it will serve you well as well.

8 comments

  1. Its really nice and expert method. But if wants to create meta keywords in pages then what have to do??

    1. Hi RankYa
      The method you use is very simple and VERY GOOD to make TAGS in posts but how can i make TAGS on pages? Can You help me?

Leave a comment

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