schema variables

#750337
  • Resolved mohamed rabie
    Rank Math free

    hello !

    i have another plugin which display matches info .. i want to use variables like ” home team ” vs “away team “inside sportevent schema in rank math
    this is screenshot from other plugin which display matches info

    https://ibb.co/pZmP2mY
    https://ibb.co/mGCZyLv

    i want to use this varibals inside rank math schema

    $data = (object) wp_parse_args(
    $data,[
    ‘match_id’ => ”,
    ‘kickoff’ => ”,
    ‘match_time’ => ”,
    ‘match_date’ => ”,
    ‘home_name’ => ”,
    ‘away_name’ => ”,
    ‘home_logo’ => ”,
    ‘away_logo’ => ”,
    ‘home_goals’ => ”,
    ‘away_goals’ => ”,
    ‘home_penalty’ => ”,
    ‘away_penalty’ => ”,
    ‘status_meta’ => ”,
    ‘status_id’ => ”,
    ‘competition’ => ”,
    ‘commentator’ => ”,
    ‘channel_name’ => ”,

    ]
    );

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello!

    Thank you for reaching out with your question about using variables inside the SportEvent schema in Rank Math. To include the “home team” and “away team” information from your plugin into the schema, you can utilize Rank Math’s variables feature.

    Based on the data structure you provided, you can use the following Rank Math variables to dynamically populate the “home team” and “away team” information in the SportEvent schema:

    • %home_name%
    • %away_name%
    • %home_logo%
    • %away_logo%

    By incorporating these variables into your schema setup, Rank Math will automatically fetch and display the corresponding “home team” and “away team” details from your plugin data.

    If you encounter any issues or need further assistance while implementing these variables, please feel free to provide more details or screenshots, and we’ll be happy to assist you further.

    Thank you for considering Rank Math for your schema needs!

    Sources:
    How to Use Schema Templates in Rank Math PRO » Rank Math
    How to Use Rank Math’s Custom Schema Generator » Rank Math
    Configuring “Schema Markup” in Rank Math » Rank Math

    Hello,

    Thank you for your patience.

    In this case, you may need to register the value into a new variable so you can use it in the schema or metadata.

    Here’s a guide on how to create custom variables in Rank Math:
    https://rankmath.com/kb/variables-in-seo-title-description/#how-to-add-custom-variables

    Once done, you can use that variable in the schema filter to fetch the matches information.

    Hope that helps.

    can you help me ?

    i used gpt and gives me this code :

    // Define your data object
    $data = (object) wp_parse_args(
    $data, [
    ‘match_id’ => “”,
    ‘kickoff’ => “”,
    ‘match_time’ => “”,
    ‘match_date’ => “”,
    ‘home_name’ => “”,
    ‘away_name’ => “”,
    ‘home_logo’ => “”,
    ‘away_logo’ => “”,
    ‘home_goals’ => “”,
    ‘away_goals’ => “”,
    ‘home_penalty’ => “”,
    ‘away_penalty’ => “”,
    ‘status_meta’ => “”,
    ‘status_id’ => “”,
    ‘competition’ => “”,
    ‘commentator’ => “”,
    ‘channel_name’ => “”,
    ]
    );

    // Function to retrieve custom variable value
    function custom_variable_callback($data_key) {
    global $data;

    // Return the value of the custom variable
    return $data->$data_key;
    }

    // Register custom variables
    add_action(‘rank_math/vars/register_extra_replacements’, function () use ($data) {
    // Loop through each key in $data and register custom variable
    foreach ($data as $key => $value) {
    rank_math_register_var_replacement(
    $key,
    array(
    ‘name’ => ucwords(str_replace(‘_’, ‘ ‘, $key)),
    ‘description’ => “Value of $key from the data object.”,
    ‘variable’ => $key,
    ‘example’ => “custom_variable_callback(‘$key’)”,
    ),
    function() use ($key) {
    return custom_variable_callback($key);
    }
    );
    }
    });

    it works and i found it in rank math
    but when i insert it in schema template it displays nothing
    https://ibb.co/LQDLVQ6
    https://ibb.co/tD83Lfj
    https://ibb.co/4KdhGCY

    any help ?

    Hello,

    Sorry, but complex modification of the filter falls out of the scope of our support. You should get in touch with the support of the plugin that displays match info, as they will be in a better position to help you get the value from their plugin and use it to create a custom variable.

    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 4 replies - 1 through 4 (of 4 total)

The ticket ‘schema variables’ is closed to new replies.