I want to add a custom name in my post title by using a variable

#365782
  • From Rank Math Snippet Editor we can add any taxonomy like %title% %sep% from drop down menu,
    but i want to use a custom variable like %spec% , which will show the value as “Full phone specifications” in my title.
    I mean now if i select %title% %sep% that time i can see in my Title Box “Apple iPhone 13 Pro – “..SO i want to create a custom variable like %spec%, so when i will select %spec% from drop-down menu after %title% %sep%, that time we can see %title% %sep% %spec% and Value will show “Apple iPhone 13 Pro – Full phone specifications”

    So for creating this custom taxonomy i found a code in your support blog and i tried to modified it for me, i am given the code below which i modified but i am not sure its right or wrong, because i am not expert in coding…
    COuld you please check that my code is right or something wrong??

    // Custom variable for the custom field from the wp_postmeta table
    add_action( ‘rank_math/vars/register_extra_replacements’, function(){
    rank_math_register_var_replacement(
    ‘spec’,
    [
    ‘name’ => esc_html__( ‘Mobile Specification’, ‘rank-math’ ),
    ‘description’ => esc_html__( ‘Full phone specifications’, ‘rank-math’ ),
    ‘variable’ => ‘spec’,
    ‘example’ => ‘Full phone specifications’,
    ],
    ‘phone_spec_callback’
    );
    });
    function phone_spec_callback() {
    return get_post_meta(get_queried_object_id(), ‘_spec’, true);
    }

Viewing 1 replies (of 1 total)
  • Hello,

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

    I tested the code you created and it should work on your end. Assuming the post meta exists on the posts, the %spec% variable should be able to generate the correct value.

    Let us know how that goes from your end.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 1 replies (of 1 total)

The ticket ‘I want to add a custom name in my post title by using a variable’ is closed to new replies.