limit %excerpt% bcs description is too long

#1059980
  • Resolved Thomas Schmidt
    Rank Math free

    We want to limit %excerpt% to 150 characters in the description. How does it work.

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

    We apologize for the issue you’re facing with the length of the %excerpt% in your descriptions. Unfortunately, Rank Math does not provide a built-in feature to limit the length of the %excerpt% variable directly within the plugin settings.

    However, you can achieve this by using a custom function in your theme’s functions.php file. Here’s a simple code snippet that you can use to limit the excerpt length to 150 characters:

    function custom_excerpt_length($text) {
        return wp_trim_words($text, 150, '...');
    }
    add_filter('the_excerpt', 'custom_excerpt_length');

    This code will trim the excerpt to 150 words and append an ellipsis (...) if it exceeds that length. Please ensure to back up your site before making any changes to the functions.php file.

    If you need further assistance or a more comprehensive setup, we recommend considering our professional setup service, which ensures your plugin is configured correctly according to the latest SEO standards. You can find more information about this service at Rank Math Services.

    Thank you for raising this concern! If you have any more questions or need further clarification, feel free to reply to this ticket.

    Sources:
    How to Limit the Number of Words in RSS Feed? » Rank Math

    Hello,

    Thank you so much for getting in touch.

    Unfortunately, that variable cannot be changed, the only way to limit how the meta description is displayed is through the filter code below:

    add_filter('rank_math/frontend/description',function($description){
            $description=mb_substr(strip_tags($description),0,150);
            return $description;
    });

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

    The filter will limit the output of the meta description you entered on the SEO meta description field but not the output of the %excerpt%.

    Hope that helps and 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 2 replies - 1 through 2 (of 2 total)

The ticket ‘limit %excerpt% bcs description is too long’ is closed to new replies.