Site logo

Archived topic

Search results excerpt

3 replies · Started by David on December 22, 2021

Viewing posts 1–4 of 4

Hello, is it possible to use a snippet description from rank math (rank_math_description) instead of an excerpt on the search results page?

Thank you, David

Hi there,

you can use the_excerpt filter:

https://developer.wordpress.org/reference/hooks/the_excerpt/

As an example:

add_filter( 'the_excerpt', function( $excerpt ) {
    $my_custom_excerpt = get_the_custom_value;
    if ( is_search() && !empty( $my_custom_excerpt )) {
        $excerpt = $my_custom_excerpt;
    }
    return $excerpt; 
} );

Of course this:

$my_custom_excerpt = get_the_custom_value;

will need updating to get the value you require. You may need to ask Rank Math how to get their description whilst in the loop. Happy to help if they can provide that bit of info

Thanx for the superfast answer, it´s working fine

I found the value:
RankMath\Helper::get_post_meta( 'description', $post_id );

May help others too...

David

Awesome - glad to hear that - and thanks for sharing the extra code :)

This archived topic is closed to new replies.