Was just wondering if there is a way to create a custom variable so that I can add my custom variable created in the Meta title of the page.
Yoast SEO has a list of variables predefined here.
It would be great if I could create a variable of my own. Is there any way to get this?
Thanks in advance!
Variables in the Yoast SEO plugin give you the power to autogenerate page titles and meta descriptions for your entire website based on a set of rules defined by content type. This is one of the many powerful tools in WordPress that make it a search engine friendly content management system.
Is Yoast SEO Premium worth it? No, it is not. The multiple focus keywords feature is pretty much useless, redirects can be setup using free redirect plugins, and nothing in Yoast Premium directly improves your SEO. It's not worth $99/year.
Snippet variables have become a staple of Yoast SEO. These variables make it possible to automate certain processes on your site. They also make it easy to change large batches of meta descriptions for instance, since you only have to change the structure of the variable – the site fills in the data automatically.
Click on Edit, and then scroll to the bottom of the screen where the Yoast SEO section is located: Enter your primary keyword into the Focus Keyphrase section. Then, click on the Edit Snippet button to enter your meta description.
You have two options for this.
If you want to change exist variable, you can do it like this:
// define the wpseo_replacements callback
function filter_wpseo_replacements( $replacements ) {
if( isset( $replacements['%%page%%'] ) ){
$replacements['%%page%%'] = 'Page x of y';
}
return $replacements;
};
// Add filter
add_filter( 'wpseo_replacements', 'filter_wpseo_replacements', 10, 1 );
And if do you want to add custom variable you can do it like this:
// define the custom replacement callback
function get_myname() {
return 'My name is Moses';
}
// define the action for register yoast_variable replacments
function register_custom_yoast_variables() {
wpseo_register_var_replacement( '%%myname%%', 'get_myname', 'advanced', 'some help text' );
}
// Add action
add_action('wpseo_register_extra_replacements', 'register_custom_yoast_variables');
I hope I was helpful to you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With