%customfield(field-name)%, HTML tag and structured data

#909232
  • Resolved Clemjam
    Rank Math free

    Hi !
    I have an issue with %customfield(field-name)% variable and structured data. If a use that variable for the description schema markup, the value of the variable shows html tag but If I use that variable for the meta description, it works fine, there is no html tag.

    For information, the custom field is from JetEngine meta field and it’s a WISIWIG field.

    You can see screenshots here : https://imgur.com/a/t1HKVVI

    Thanks by advance,
    ClemJam

Viewing 12 replies - 1 through 12 (of 12 total)
  • Hello,

    We apologize for the issue you are facing with the %customfield(field-name)% variable and structured data. The behavior you’re experiencing is likely due to how the structured data handles HTML content compared to how the meta description processes it.

    When using WYSIWYG fields, the output may include HTML tags, which can affect how the structured data is rendered. Unfortunately, the context does not provide a specific solution for this issue with JetEngine meta fields.

    We recommend checking if there are any filters or settings in JetEngine that allow you to strip HTML tags before passing the value to the structured data. Alternatively, you might consider using a different field type that outputs plain text if possible.

    If you need further assistance, please reply to this ticket, and a human agent from the Rank Math Support team will take over and provide more tailored help.

    Thank you for raising this concern!

    Hello,

    We can forcibly remove the HTML tags from that field via our custom variable filter code. Here’s a code you can follow:

    add_action( 'rank_math/vars/register_extra_replacements', function(){
        rank_math_register_var_replacement(
            'shortcode_var_name', [
                'name'        => esc_html__( 'Author name', 'rank-math' ),
                'description' => esc_html__( 'Author description', 'rank-math' ),
                'variable'    => 'shortcode_var_name', /* the actual variable: %shortcode_var_name% */
                'example'     => shortcode_var_name_call_back(),
            ],
            'shortcode_var_name_call_back'
        );
    });
    
    function shortcode_var_name_call_back(){
        global $post;
        $field_value = get_field('resume', $post->ID);
        return wp_strip_all_tags($field_value);
    }

    You may refer to this guide on how to add filters to your website: https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Let us know how that goes. Looking forward to helping you.

    Hi !
    Thanks for your help ! Unfortunatly, your code doesn’t work. When I try to save my functions.php, I have that error :
    ” Vos modifications de code PHP ont été annulées en raison d’une erreur sur la ligne 82 du fichier wp-content/themes/bricks-child/functions.php. Veuillez la corriger et réessayer d’enregistrer. Uncaught Error: Call to undefined function get_field() in wp-content/themes/bricks-child/functions.php:82 Stack trace: #0 wp-content/themes/bricks-child/functions.php(74): shortcode_var_name_call_back() #1 wp-includes/class-wp-hook.php(324): {closure}() #2 wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(”, Array) #3 wp-includes/plugin.php(565): WP_Hook->do_action(Array) #4 wp-content/plugins/seo-by-rank-math/includes/traits/class-hooker.php(90): do_action_ref_array(‘rank_math/vars/…’, Array) #5 wp-content/plugins/seo-by-rank-math/includes/replace-variables/class-manager.php(185): RankMath\Replace_Variables\Base->do_action(‘vars/register_e…’) #6 wp-includes/class-wp-hook.php(324): RankMath\Replace_Variables\Manager->setup(‘theme-editor.ph…’) #7 wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) #8 wp-includes/plugin.php(517): WP_Hook->do_action(Array) #9 wp-admin/admin-header.php(118): do_action(‘admin_enqueue_s…’, ‘theme-editor.ph…’) #10 wp-admin/theme-editor.php(152): require_once(‘/home/arkp0816/…’) #11 {main} thrown”

    Any idea to solve it ?
    Best regards,
    ClemJam

    Hello,

    Could you please share the screenshot of how you have added the filter on your site so we can check?

    You can upload screenshots using this tool and add the link here.

    You can add it to the sensitive data section by editing your first post

    Sensitive Data Section

    It is completely secure, and only our support staff has access to that section.

    Looking forward to helping you.

    Hello,

    Try using this code instead:

    add_action( 'rank_math/vars/register_extra_replacements', function(){
        rank_math_register_var_replacement(
            'shortcode_var_name', [
                'name'        => esc_html__( 'Author name', 'rank-math' ),
                'description' => esc_html__( 'Author description', 'rank-math' ),
                'variable'    => 'shortcode_var_name', /* the actual variable: %shortcode_var_name% */
                'example'     => 'shortcode_var_name_call_back',
            ],
            'shortcode_var_name_call_back'
        );
    });
    
    function shortcode_var_name_call_back(){
        global $post;
        if ( function_exists('jet_engine') ) {
            $field_value = jet_engine()->listings->data->get_meta('resume', $post->ID);
            return esc_html( wp_strip_all_tags( $field_value ) );
        } else {
            return ''; // Return an empty string or a default value if JetEngine is not available
        }
    }

    If that does not work, then please share access to your website with us so we can help investigate the issue. Please follow these steps:

    • Edit the first post on this ticket and include your WordPress logins in the Sensitive Data section. This is a secure section that only our support staff can access.
    • Make sure you take a complete backup of your website before sharing the information with us.
    • If you prefer, you can use this plugin to generate a temporary login URL to your website and share that with us instead: https://wordpress.org/plugins/temporary-login-without-password/
    • You can also use this plugin to monitor what changes our staff might make on your website (if any): https://wordpress.org/plugins/wp-security-audit-log/

    We appreciate your cooperation and patience. Thank you for choosing Rank Math.

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Hello,

    The issue here is that the jetengine’s function to retrieve a custom field value is not working.

    Since the resume meta data is stored in your website’s wp_postmeta, we instead used WordPress’s standard way of retrieving the meta data for resume and it now works on your website.

    
    $resumeVal = get_post_meta( $post->ID, 'resume', true );

    From now on, you can use this variable for your pages with resume fields: %rm_field_resume%

    Hope that helps.

    Ok, there is no error anymore but the code doesn’t seem to be effective. As you can see on the screenshot, there is still html tags in the schema validator.

    https://imgur.com/a/1ZCr4GQ

    Hello,

    You were still using the old variable and after replacing that with the new variable created, the Schema markup updated and no longer shows the HTML in the description.

    There’s only HTML showing for the title because the page contains HTML inside it.

    Don’t hesitate to get in touch if you have any other questions.

    You’re a master, it works, thanks a lot !
    Have a good day,
    ClemJam

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

Viewing 12 replies - 1 through 12 (of 12 total)

The ticket ‘%customfield(field-name)%, HTML tag and structured data’ is closed to new replies.