Hello @wooq123
Thank you for contacting the support.
Assuming you are on the latest version of the plugin, in WooCommerce products, the short description is stored in the excerpt field.
By default, we are adding excerpts to the SEO Description. You can use the below filter to change that behavior:
https://rankmath.com/kb/filters-hooks-api-developer/#change-meta-description
Hope that helps.
Will this only affect the auto generated excerpt for products that don’t have a custom excerpt? Also, when I apply this I don’t see any change on preview excerpt when editing a product.
Hello @wooq123
In WooCommerce’s product, the short description is stored in the excerpt field.
By default, we are adding the excerpts to the SEO Description. You can use the below filter to change that:
https://rankmath.com/kb/filters-hooks-api-developer/#change-meta-description
Hope that helps. Thank you.
Adding that filter to my child theme’s functions.php file has not changed the behavior, and I’m still seeing my product short descriptions in the preview section when I edit products. Are there any plans to simply add a setting into the plugin that changes the source of the default excerpt? I imagine I’m not the only one who doesn’t one excerpts generated from a short description.
Hello @wooq123
Please use the following code in your themes’s functions.php file to show excerpt from the main content:
add_action( 'rank_math/frontend/description', function( $description ) {
if ( ! is_singular() ) {
return $description;
}
global $post;
$desc = RankMath\Post::get_meta( 'description', $post->ID );
if ( $desc ) {
return $desc;
}
if ( empty( $post ) || empty( $post->post_content ) ) {
return $description;
}
$keywords = RankMath\Post::get_meta( 'focus_keyword', $post->ID );
$post_content = RankMath\Paper\Paper::should_apply_shortcode() ? do_shortcode( $post->post_content ) : $post->post_content;
$post_content = \preg_replace( '/<!--[\s\S]*?-->/iu', '', $post_content );
$post_content = wpautop( $post_content );
$post_content = wp_kses( $post_content, [ 'p' => [] ] );
// 4. Paragraph with the focus keyword.
if ( ! empty( $keywords ) ) {
$regex = '/<p>(.*' . str_replace( [ ',', ' ', '/' ], [ '|', '.', '\/' ], $keywords ) . '.*)<\/p>/iu';
\preg_match_all( $regex, $post_content, $matches );
if ( isset( $matches[1], $matches[1][0] ) ) {
return $matches[1][0];
}
}
// 5. The First paragraph of the content.
\preg_match_all( '/<p>(.*)<\/p>/iu', $post_content, $matches );
return isset( $matches[1], $matches[1][0] ) ? wp_html_excerpt( $matches[1][0], 160 ) : '';
});
Hope that helps. Thank you.