How can I change the tag contents of individual Wordpress posts?

I want to add a meta tag for keyword. I use Yoast SEO but even though I specify the focus keyword, no keyword is added in the meta tag of the page's HTML.

Please help me with this or suggest alternatives.

Do I need to use costume fields? If so, how?

  • 1
    You'd need a plugin that does this. The Focus Keyword in Yoast is not the same thing as the meta tag for keywords. The keywords meta tag is utterly useless though, which is why not even Yoast has this feature. Sep 20, 2018 at 13:10
  • Meta keywords are really only useful for rare cases when you're using a custom search engine and you are restricted in what fields it will parse, so if you don't have that situation, do rethink why you are adding them.
    – WebElaine
    Sep 20, 2018 at 14:24

2 Answers 2


I would read this article, its from Yoast. I don't think you are understanding what the focus keyword feature does. This article talks about that as well as how adding the keyword meta tag is a waste of time (in most cases).

I wouldn't worry about adding it BUT if you still want to I would add a custom field. This is easiest done with ACF. You can easily create a text field and have it show on every page. Then in your header.php just add something like this...

 <meta name="keywords" content="<?php the_field('my_field'); ?>">

Unless you truly need the extra functionality in ACF, just use Core's built-in custom fields - just go to the top of the page, Screen Options, and make sure they're showing. Then carefully make sure to name the field the same thing every time. You should also be sure to create a child theme rather than editing your existing one, so your code doesn't get overwritten when your theme updates, and then make the call conditional, so if you haven't added any keywords no empty meta tag is added. This code will also allow you to add multiple keywords.

Assuming your custom field's name is meta_keywords:

// false returns all values
$keywords = get_post_meta($post->ID, 'meta_keywords', false);
// if any were found
if(count($keywords) > 0) {
    // convert the array to comma-separated string and output
    $all_keywords = implode(',', $keywords); ?>
    <meta name="keywords" content="<?php echo $all_keywords; ?>"><?php
// otherwise don't output meta keywords tag at all

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.