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

By RankYa

RankYa is a digital services provider dedicated to growing your sales and business website's results. Highly experienced technical problem solver, Google products expert with proven 'Social Media Marketing' skills, RankYa (100% Australian Owned and Operated) is dedicated to helping small businesses to grow.

We're looking forward to contributing towards your online success. Contact Us.

10 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?

Questions? Leave a Comment!

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