Federico
asked 1 month ago
I need to optimize the RankMath markup schema settings for EMO Questalk Pro pages, but I can't find tags such as %title% or %description% anywhere.
I would appreciate your help in this regard. Thank You F
2 Answers
tech Staff
answered 1 month ago

You can add this code to the functions.php file of your theme. And from your backend > Questions> Edit Question, you can use %%question_tag%%

add_action( 'wpseo_register_extra_replacements', function() {

//error_log('Yoast custom variable registered: %%question_tag%%');
wpseo_register_var_replacement(
'%%question_tag%%',
function() {
global$post;
if ( ! $post ) {
return'';
}
$tags = get_the_terms( $post->ID, 'emqa-question_tag' );
if ( ! empty( $tags ) && ! is_wp_error( $tags ) ) {
$names = implode( ', ', wp_list_pluck( $tags, 'name' ) );
// error_log('Yoast %%question_tag%% = ' . $names);
return$names;
}
return'';
},
'advanced',
__( 'Show tag of emo questalk pro (taxonomy emqa-question_tag)', 'emo-questalk-pro' )
);
});

 

The code working for Yoast SEO plugin.

The Yoast hook has run.
The replacement value works when rendering on the frontend.
But in the backend preview (Yoast snippet editor), it still shows %%question_tag%%.

Explanation
This is the default behavior of Yoast:
Many custom variables created with wpseo_register_var_replacement() only work on the frontend (in <title> and <meta> when rendered on the site).
In the backend preview, Yoast only renders its built-in variables (%%title%%, %%excerpt%%, %%category%%, …). Custom variables will almost always appear in raw form (%%myvar%%).

Federico
answered 1 month ago
Hi,  thank You But I use RankMath Plug in.  Do you have any experience in using it? 
techStaff
replied 1 month ago

If you are using the RankMath plugin, you can use this: %customterm(emqa-question_tag)%

Please login or Register to submit your answer