defining values of extra variables

#474071
  • Resolved Francois Gonin
    Rank Math free

    Hello

    Using the action hook from your doc for adding extra variables works fine to create the variable. But how to add the value behind the variable?
    …the ‘custom_variable_callback()’ adds only an example for the preview !?

    Is there another hook for this? (which I can’t find in the docs).

    Thanks for your help
    François

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for contacting Rank Math support today and bringing your concern to our attention.

    The callback function should return a string value that the custom variable uses to display a value on the frontend.

    Please refer to this example code instead:

    add_action( 'rank_math/vars/register_extra_replacements', function(){
    	rank_math_register_var_replacement(
    	   'shortcode_var_name', [
    	   'name'        => esc_html__( 'Author name', 'rank-math' ),
    	   'description' => esc_html__( 'Author description', 'rank-math' ),
    	   'variable'    => 'shortcode_var_name', /* the actual variable: %shortcode_var_name% */
    	   'example'     => shortcode_var_name_call_back(),
    	   ],
    	   'shortcode_var_name_call_back'
       );
    });
    function shortcode_var_name_call_back(){
    	return "THE VALUE HERE...";
    }

    Hope that helps. Looking forward to helping you with this one.

Viewing 1 replies (of 1 total)

You must be logged in to reply to this ticket.