Meta description is truncated

#55695
  • Resolved Zhao Han
    Rank Math free

    I have %exerpt% for my post meta description.

    I see the code is generating the first paragraph as the description (line 297 in includes/replace-variables/class-post-variables.php).

    But my meta description is truncated. How can I show the full paragraph?

Viewing 8 replies - 1 through 8 (of 8 total)
  • I tried to use the same code for my howto schema description generation (line 8 of the HTML source). It works. Very wierd.

    `
    $post_content = get_the_content();
    \preg_match_all( ‘/<p>(.*)<\/p>/iu’, $post_content, $matches );
    return isset( $matches[1], $matches[1][0] ) ? $matches[1][0] : $excerpt;
    `

    Hello,

    Thank you for contacting Rank Math today.

    The excerpt options takes complete words that fit within a SEO description recommendation of 160. This seems to be the same thing happening on your page as according to the source from my end.

    Looking forward to helping you. Thank you.

    ​​​​​​

    Hi Michael, is there a way to override the limit?

    Thanks,
    Zhao

    Hello,

    Thank you for the follow up.

    Search engines show a limited length of site description. You can try and key in the description manually in Rank math metabox, however this might not all appear search engine.

    Hope this helps you. Thank you.

    ​​​​​​

    Is there any way to change it in the code?

    Hello,

    Thank you for the follow up.

    You can add the following code into your function.php file.

    /**
     * Allow changing the meta description sentence from within the theme.
     *
     * @param string $description The description sentence.
     */
    add_filter( 'rank_math/frontend/description', function( $description ) {
    	if(is_product()){
    		return wp_html_excerpt($description, 160 );
    	}
    	return $description;
    });

    You can change the 160 value and use the length you wish to.

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    I don’t think the code you provided works.

    I am not using WooCommerce so I guess is_product will always return false.

    The code truncates to 160 characters exactly as well, which is exactly I am trying to avoid.

    Will it possible to have an advanced option to choose or disabe/enable the number of characters? Where can I submit a feature request?

    Hello,

    Thank you for the follow up.

    The code I provided is a sample code which you can customize in relation to what you wish to do. For instance you can change it as following:

    /**
     * Allow changing the meta description sentence from within the theme.
     *
     * @param string $description The description sentence.
     */
    add_filter( 'rank_math/frontend/description', function( $description ) {
    	if(is_*your_post_type()){
    		return wp_html_excerpt($description, 200 );
    	}
    	return $description;
    });

    Looking forward to helping you. Thank you.

    ​​​​​​

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

The ticket ‘Meta description is truncated’ is closed to new replies.