Yoast SEO

How to update the Yoast SEO title and description programmatically

You can easily put custom metas into your code thanks to the plugin Yoast SEO: meta title and meta description.

There is no problem if you want to edit it manually but you can’t do it through Yoast SEO API.

The good news is that Yoast SEO uses classical WordPress post meta to store values. So you can update it like any post meta.

Here is an example:

update_post_meta( $id, '_yoast_wpseo_metadesc', 'My post description' );
update_post_meta( $id, '_yoast_wpseo_title', 'My post title' );

Change the $id by your post id and your post will be automatically updated! nothing else to do.

If you create a post programmatically, you can include the code above just after the wp_insert_post() function.

Still stuck ? You can contact an expert.

Leave a Comment

Your email address will not be published.

You may also like