Shortcode inside FAQ Schema

#382898
  • Resolved BeichtstuhlTV
    Rank Math free

    Hello,

    is there a way i can use a shortcode inside a schema?

    To be more specific:

    I’m using this plugin ( Click ) to display the current age of persons. Now i want to use it inside the faq schema with classic editor like:

    Question: How old is xy?

    answer: xy was born on 01.01.1990 and is currently [current_age_shortcode] years old.

    If i now use the rankmath shortcode to display the schema inside the post it is not able to show the age but only the used shortcode as it is.

    Is there a way to allow schema to convert the shortcode and show the result of the shortcode in this example “22”?

    Or do you have another idea on how i will be able to use it as it would be really important for me to show the current age dynamically updated each year besides the birthdate.

    Thanks in advance for your help!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Prabhat
    Rank Math agency

    Hello,

    Thank you for contacting the support.

    You can create a custom variable and use that variable in the Schema to get the desired output. To create the variable, you can use this filter: https://rankmath.com/kb/filters-hooks-api-developer/#add-extra-variables

    Here’s an example code:

    add_action( 'rank_math/vars/register_extra_replacements', function(){
            rank_math_register_var_replacement(
                'get_current_age',
                [
                    'name'        => esc_html__( 'Gets the current age.', 'rank-math' ),
                    'description' => esc_html__( 'Gets the current age.', 'rank-math' ),
                    'variable'    => 'get_current_age',
                    'example'     => 'get_current_age_callback()',
                ],
                'get_current_age_callback'
            );
        });
        function get_current_age_callback() {
            // Add the logic here
            return $age;
        }

    By modifying and adding the above filter to the website, you will be able to use the variable %get_current_age% that would contain the current age of the user.

    Here’s a guide that you can follow to add the code to the website:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Hope this helps.

    Thank you.

    thanks could make it work!

    I have another question regarding faq schema and it’s best use:

    What’s the best lenght for answers? I normally have up to 150 words as an answer – is this to long and should i rewrite it and consider using only the most important facts of it?

    Would Google display the whole answer even if it’s like this long?

    Hello,

    You should keep it simple, short, and accurate for the best results. The recommended length for FAQ answers is 160-200 characters.

    Please refer to the following guide to learn more about FAQ best practices: https://rankmath.com/blog/faq-schema/#best-practices

    Hope this helps. Let us know if you need any other assistance.

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

The ticket ‘Shortcode inside FAQ Schema’ is closed to new replies.