Output Rank Math’s variables into HTML?

#454014
  • Resolved Cosmin
    Rank Math free

    Is there a way to output Rank Math’s variables directly into HTML (maybe by using a shortcode or directly with PHP)?

    I am referring to the same variables that Rank Math uses to generate titles and meta descriptions.

    E.g. %title% or %excerpt% or %term% can easily be outputted with <?php echo the_title(); ?>, <?php echo the_excerpt(); ?> and <?php single_term_title(); ?>

    But what about others like %pt_single% or %pt_plural% or %_gd_in_location%, which will output the name of the CPT (singular or plural), and the location set by another plugin?

    Rank Math has

    Thank you in advance.

Viewing 1 replies (of 1 total)
  • Hello,

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

    This would require you to create a shortcode or you can directly output it as you did for the title, excerpt, and term.

    You need to process the variable you wish to render on the front end so the correct value will show. You may refer to this example code:

    add_shortcode('rm_title', 'custom_shortcode_rm_title');
    
    function custom_shortcode_rm_title() {
      return RankMath\Helper::replace_vars("%pt_single%");
    }

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    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 ‘Output Rank Math’s variables into HTML?’ is closed to new replies.