-
hi, im using yoast right now and have custom variables with this code in function:
if (defined('WPSEO_VERSION')) { wpseo_register_var_replacement('%%en_name%%', 'en_name_replace', 'advanced', 'my title'); } function en_name_replace($var, $args) { $replacement = null; if(isset($args->term_id)) { $en_name = get_term_meta($args->term_id, '_name_en', true); if(!empty($en_name)) { $replacement = $en_name; } } return $replacement; }
i am moving to rank math and i need this variable for title. i found this :
/** * Filter to add custom variables */ add_filter( 'rank_math/vars/replacements', function( $vars ) { return $vars; });
and
/** * Action: 'rank_math/vars/register_extra_replacements' - Allows adding extra variables. */add_action( 'rank_math/vars/register_extra_replacements', function(){ rank_math_register_var_replacement( 'custom_variable_slug', [ 'name' => esc_html__( 'Custom variable name.', 'rank-math' ), 'description' => esc_html__( 'Custom variable description.', 'rank-math' ), 'variable' => 'custom_variable_slug', 'example' => 'custom_variable_callback()', ], 'custom_variable_callback()' ); });
can someone please help me how to use it?
Thanks.
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
The ticket ‘adding Custom Variable’ is closed to new replies.