add new veriable for titles and description

#32498
  • Resolved Fred
    Rank Math free

    Hi im using yoast but i want use rank math. But i need speical veriable. For example im using my category title’s (not everyone) next year (2021) when i wrote title %%nextyear%% automaticly show 2021 on title. can you help about this? its must work post, categories title’s and descriptions. i hope you understand me.. sorry poor english.

    • This topic was modified 4 years, 8 months ago by Fred.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Fred
    Rank Math free

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Todd
    Rank Math free

    Hi Fred,

    Thanks for getting in touch with us.

    You can use this filter to register your own variable and show it in the drop down at WordPress Dashboard > Rank Math > Titles & Meta >

    /**
     * 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()'
     );
    });

    We are assuming you know a bit of PHP to make it work.

    If not, please let us know so our team can help you further.

    Thank you.

    Fred
    Rank Math free

    hey, can you answer me pls. im want use your plugin.

    Fred
    Rank Math free

    Hi, thanks for answer. i did something in admin panel everything seems okey but when i publish article or new category i dont see on title new veriable.

    admin place: http://prntscr.com/r3og1rhttp://prntscr.com/r3okov

    but i dont see nothing on title or desc. after publish. http://prntscr.com/r3ohsk

    example code i used in functions.php:

    /**
     * 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(
     'years',
     [
     'name'        => esc_html__( 'Custom variable name.', 'rank-math' ),
     'description' => esc_html__( 'Custom variable description.', 'rank-math' ),
     'variable'    => 'years',
     'example'     => '2020-2021',
     ],
     'custom_variable_callback()'
     );
    });

    Hi Fred,

    Thank you for getting back to us.

    You need to modify the callback on your code and add the return type as shown below:

    /**
     * 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(
     'years',
     [
     'name'        => esc_html__( 'Custom variable name.', 'rank-math' ),
     'description' => esc_html__( 'Custom variable description.', 'rank-math' ),
     'variable'    => 'years',
     'example'     => '2020-2021',
     ],
     'my_variable_callback'
     );
    
    });
    function my_variable_callback(){
    	return '2020';
    }

    I hope this info helps.

    Fred
    Rank Math free

    Hello! yes it has helped many thanks. Well I want to add more than one variable. Need to write the same code one after the other? for example, i want add 4-5 another veriable.
    So what kind of encoding i need for 4-5 different variables? such as %years% = 2020-2021,% examyear% = 2020% life% = 2023.

    Todd
    Rank Math free

    Hi Fred,

    As much as we would love to offer customized solution to each and every user we have, it just isn’t possible for a small company like ours with limited resources.

    Unfortunately, you will need to make further changes on your own. We have given you the basic template of making it work.

    If you need help with anything else, please open a new support ticket here so we can help

    We are always here for assistance.

Viewing 7 replies - 1 through 7 (of 7 total)

The ticket ‘add new veriable for titles and description’ is closed to new replies.