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.

A LIRE AUSSI  How to add shipping VAT into WooCommerce programmatically

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

Leave a Comment

Your email address will not be published.

You may also like
gdpr
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.