[Resolved] Search results excerpt

Home Forums Support [Resolved] Search results excerpt

Home Forums Support Search results excerpt

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2056862
    David

    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

    #2056978
    David
    Staff
    Customer Support

    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

    #2057060
    David

    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

    #2057619
    David
    Staff
    Customer Support

    Awesome – glad to hear that – and thanks for sharing the extra code 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.