<?php | |
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/ | |
/* Remove Yoast SEO Change existing title or meta template variable | |
* Credit: Moshe Harush | |
* https://stackoverflow.com/questions/36281915/yoast-seo-how-to-create-custom-variables | |
* Last Tested: Unknown | |
*/ | |
// 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 ); |
<?php | |
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/ | |
/* Remove Yoast SEO Add custom title or meta template variables | |
* Credit: Moshe Harush | |
* https://stackoverflow.com/questions/36281915/yoast-seo-how-to-create-custom-variables | |
* Last Tested: Nov 29 2018 using Yoast SEO 9.2.1 on WordPress 4.9.8 | |
******* | |
* NOTE: The snippet preview in the backend will show the custom variable '%%myname%%'. | |
* However, the source code of your site will show the output of the variable 'My name is Moses'. | |
*/ | |
// 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'); |
This comment has been minimized.
This comment has been minimized.
@mrayushh The snippet preview in the backend will show the custom variable |
This comment has been minimized.
This comment has been minimized.
It's still unsolved bug from Yoast. The value appears in source code but not on the snippet preview. |
This comment has been minimized.
This comment has been minimized.
yo pongo 1 codigo y todo perfecto, pero al ponerlo varias veces, se cae todo wordpress, help!! |
This comment has been minimized.
This comment has been minimized.
I put 1 code and everything perfect, but when you put it several times, all wordpress falls, help !! / TITULO SEO 1 // define the custom replacement callback // TITULO SEO 2 // define the custom replacement callback // META SEO 1 // define the custom replacement callback // META SEO 2 // define the custom replacement callback |
This comment has been minimized.
This comment has been minimized.
thank you, this code help me to resolve an detail in my project |
This comment has been minimized.
This comment has been minimized.
I have created a quick article with screenshot and example variable current year and current month. Read more https://maheshwaghmare.com/doc/yoast-seo-custom-template-variable/ |
This comment has been minimized.
Can you please give a update on it because i tried it with yoast 9.0.2 and it created the variable but unable to get the data stored under the variable. It shows it same as %%mytitle%%, it was supposed to show 'my name is moss'