-
Does Rankmath Pro Schema support reading shortcode from php?
-
Hello,
We apologize for the issue you are facing. Unfortunately, the provided context does not specify whether Rank Math Pro Schema supports reading shortcodes from PHP.
We recommend replying to your ticket with this question, and a human agent from the Rank Math Support team will be able to assist you further. Thank you for your understanding!
Hello,
You may need to register the shortcode value into a custom variable and use it in the schema generator.
Here’s the filter you can use for that:
https://rankmath.com/kb/variables-in-seo-title-description/#how-to-add-custom-variablesLooking forward to helping you.
Thank you for quick response, Can you please give me example of shortcode value into a custom variable look like?
Php shortcode
add_shortcode('productname', 'product_name'); function product_name() { $message = 'ipad pro'; return $message; }Hello,
You would need to pass the same code of the function for the shortcode inside the callback.
Since you are just assigning a variable here, the code for the callback would be the following:
add_action( 'rank_math/vars/register_extra_replacements', function(){ rank_math_register_var_replacement( 'productname', [ 'name' => esc_html__( 'Product Name', 'rank-math' ), 'description' => esc_html__( 'Product Name', 'rank-math' ), 'variable' => 'productname', 'example' => productname_call_back(), ], 'productname_call_back' ); }); function productname_call_back() { $message = 'ipad pro'; return $message; }Don’t hesitate to get in touch if you have any other questions.
Hi Miguel,
Thanks for the solution unfortunately didn’t work, Could you help me see the code below?
Added shortcode

The result
// Register Rank Math Pro custom variables add_action('rank_math/vars/register_extra_replacements', function(){ // Register 'homename' variable rank_math_register_var_replacement( 'homename', [ 'name' => esc_html__('Home Name', 'rank-math'), 'description' => esc_html__('Home Name', 'rank-math'), 'variable' => 'homename', 'example' => 'Tampines Residences', ], 'get_home_name' ); }); function get_home_name() { return 'Tampines Residences'; } add_shortcode('homename', 'get_home_name');Hello,
Thank you for your patience.
We have updated the filter so you can replace it with this one:
// Register Rank Math Pro custom variables add_action('rank_math/vars/register_extra_replacements', function(){ // Register 'homename' variable rank_math_register_var_replacement( 'get_home_name', [ 'name' => esc_html__('Home Name', 'rank-math'), 'description' => esc_html__('Home Name', 'rank-math'), 'variable' => 'get_home_name', 'example' => 'get_home_name_callback', ], 'get_home_name_callback' ); }); function get_home_name_callback() { return 'Tampines Residences'; }Once done, to use the variable, you may need to add
%get_home_name%variable in the description and name fields.Hope that helps.
You must be logged in to reply to this ticket.