How to enable WordPress shortcodes in the Yoast SEO fields

Posted on: May 26, 2024

Written by: Mick Sherry

If you’re wondering how to make a shortcode work inside one of the Yoast SEO’s plugin text fields, you’ve found the right guide.

functions.php code to enable shortcodes in Yoast SEO

All you have to do is go to Appearance –> Editor –> functions.php –> scroll to the bottom of the file and copy/paste the following code snippet:

// Enable shortcodes in Yoast SEO title.
add_filter('wpseo_title', 'do_shortcode');

// Enable shortcodes in Yoast SEO Meta Description text box.
add_filter('wpseo_metadesc', 'do_shortcode');

// Enable shortcodes in Yoast SEO Open Graph title field.
add_filter('wpseo_opengraph_title', 'do_shortcode');

// Enable shortcodes in Yoast SEO Open Graph description textbox.
add_filter('wpseo_opengraph_desc', 'do_shortcode');

// Enable shortcodes in Yoast SEO Twitter title field.
add_filter('wpseo_twitter_title', 'do_shortcode');

// Enable shortcodes in Yoast SEO Twitter description
add_filter('wpseo_twitter_description', 'do_shortcode');

Once you’ve added the above code snippet to your functions.php file, you can run and output the text from a shortcode in any of the Yoast SEO meta fields.

Why you might need to do shortcodes in the Yoast SEO plugin?

Adding this functionality can be useful if you are templating a set of pages or posts and you want to dynamically insert some text into the SEO page title or meta description.

Want an example of how I take advantage of using shortcodes with the Yoast plugin to save time and enhance my SEO?

Leave me a comment on this post and I can explain some of the ways I like to use this little trick.

Click-To-Call Send Message