skip to Main Content

Could you tell me please, what is the best way to add/update SEO metakeywords programmatically?

i looked it up and found on this article how to update meta title and meta desc : https://ehikioya.com/how-to-update-yoast-seo-fields-programmatically/

when i tried to update the meta key words with the same code it wont work.

$updated_title = update_post_meta($post_id, ‘_yoast_wpseo_title’, $metatitle); //working
$updated_desc = update_post_meta($post_id, ‘_yoast_wpseo_metadesc’, $metadesc); //working
$updated_kw = update_post_meta($post_id, ‘_yoast_wpseo_metakeywords’, $metakeywords); // not working

I’m writing a plugin for import products and categories in WooCommerce.

2

Answers


  1. Chosen as BEST ANSWER

    after few hours i found the right key, if anyone ever come across this issue here is the soultion.

    using the key : "_yoast_wpseo_focuskw"

    $updated_kw = update_post_meta($product_id, '_yoast_wpseo_focuskw', $metakeywords);
    

  2. I believe that Yoast SEO removed metakeywords. Searching the plugin code only title and metadesc still exist. Here is an article from Yoast explaining it
    Meta keywords: why we don’t use them

    You may instead need to try using their Focus keyword meta ie _yoast_wpseo_focuskw

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search