I would like to use custom shortcodes in Yoast SEO Plugin, but I can’t bring it to work. I want to put custom time specifications in the meta title.
This is my shortcode:
function time_yoast_shortcode() {
$year = date('Y');
return $year;
}
add_shortcode('yyyy', 'time_yoast_shortcode')
This is how I want the title in the Yoast to look like: THIS IS MY EXAMPLE POST in the year [yyyy]
Any ideas how I can make my shortcode work in Yoast?
5
Answers
If you’d like your post to show the date at the end of your SEO Title of Yoast try: %%date%% within the SEO Title field of the yoast plugin on that particular post. For just the year use %%currentyear%%.
In the event you’d like to do this globally you can do this within the post titles & metas section of the plugin settings.
Here is a full list of their varables
For anyone looking to add shortcode support for Yoast SEO’s Meta Title, here’s how I handled it. This code adds full shortcode support for Meta Title and adds a custom shortcode [year] to output the current year. Add this code to functions.php:
We’ve created a WordPress plugin to do/run/show shortcodes for Yoast SEO. It is currently in version 2.1.1. Unfortunately we cannot upload it to the WordPress repository due to possible copyright infringement (which is not true). So you may download, use parts of our code and use install the whole plugin directly from here:
https://denra.com/wordpress/plugins/do-shortcodes-for-yoast-seo/
We will continue updating the plugin with new features when needed but you may need to keep the URL to the plugin page on our website because we cannot upload to WordPress.org
Add this code in functions.php file and it will work:
Now you can use [year] in a title to post current year.
i am writing this code by considering you have yoast seo plugin