WordPress Meta Keywords by RankYa

WordPress Meta Keywords by RankYa

 In WordPress

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 guru/s 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.

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? 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 //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 itemprop="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 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 check out public assets section of RankYa blog

Recommended Posts
Showing 6 comments
  • JOSHUA
    Reply

    I WATCH YOUR VIDOE ON YOU AND WAS DIRECTED…I HOPE THIS WILL WORK FOR MY BLOGS…

  • Nishan SIngh
    Reply

    Very nice Guide and Quality content Can wordpress meta is helping in SEO

  • Web design company
    Reply

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

    • Michał
      Reply

      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?

      • RankYa
        Reply

        Hello Michal, this has to be done manually for WordPress pages:
        if ( is_page('somepagepermalink') )

  • Chamara Vijendra
    Reply

    Thank you very much Rankya

Leave a Comment

0

Start typing and press Enter to search

How to Use Yoast WordPress SEO PluginWordPress Optimization by RankYa