WordPress Meta Keywords by RankYa

WordPress CMS for Blog Posting

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 SEO gurus at Yoast think that you shouldn’t doesn’t mean that you shouldn’t.).

Code that Generates Meta Keywords Tag

<?php
global $wp_query;
if ( is_single() ) : ?>
<?php //do this check first
$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; // tag 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; // tag name
if($key == $last_key) {
echo $tag_name;
} else {
echo $tag_name.', ';
}
}
?>">
<?php //smart to else it
else: ?>
<!--do nothing for if NO posttags-->
<?php endif; // end if posttag check ?>
<?php endif; // end if single check ?>

How to Use It?

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) header.php before you modify it

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 //do this check first
$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; // tag 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; // tag name
if($key == $last_key) {
echo $tag_name;
} else {
echo $tag_name.', ';
}
}
?>">
<?php endif; // end if posttag check ?>
<?php elseif ( is_product() ): ?>
<?php //do this check first
$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 name="keywords" content="<?php
foreach ( $terms as $term => $value) {
$rankyacheck = $value->slug;
if($term == $last_key) {
echo $rankyacheck;
} else {
echo $rankyacheck.', ';
}
}
?>">
<?php endif; // end if product check ?>
<?php //smart to else it
else: ?>
<!--do nothing for if NO posttags-->
<?php endif; // end if single check ?>

How to Use It?

Same process as 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 RankYa WordPress Optimization Mastery.

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 SEO codes like this? Simply share this post and visit RankYa blog and YouTube channel often

Author: RankYa

RankYa: Online Entrepreneur, Qualified Web Developer, Google AdWords and Google Analytics Certified Professional. Specialist in: SEO, Website Optimization, WordPress, Structured Data, JSON-LD, Microdata, Microformats, RDF, Schema.org Vocabulary, HTML5, Advanced Image Optimization, Google Search Console, Google Webmaster Guidelines, Social Media Marketing, Facebook marketing and YouTube video ranking.

Thank you for sharing this blog post. Description: 'WordPress Meta Keywords by RankYa shares custom codes to generate meta keywords tag automatically.'