Support » Plugin: WordPress SEO Plugin - Rank Math » Truncate length of meta description from custom field?

  • Resolved Bjarne

    (@oldrup)


    On the page linked, I’m using RankMath for meta data 🙂

    The meta description is fetched from %customfield(field-name)%

    In some cases, the data in the field can be rather long, maybe 500 characters.

    Is there any way to make RankMath truncate the text fetched from a custom field, to adhere to best practices for meta description, say 160 characters?

    Best regards
    Bjarne

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author Rank Math

    (@rankmath)

    Hello @oldrup

    Thank you for contacting the support.

    You can add the following code to your theme’s functions.php file:

    add_filter( 'rank_math/frontend/description', function( $description ) {
        return substr( $description, 0, 160 );
    });

    Hope that helps.

Viewing 1 replies (of 1 total)
  • The topic ‘Truncate length of meta description from custom field?’ is closed to new replies.