Add link to excerpt if is on search and is custom post type

Question

I want to display the excerpt and add a link to the bottom if the searched result if from my custom post type. What filter should I use?

if ( is_search() && get_post_type() == 'books' ) {
    
    function exceprt_link( $search_excerpt ) {
        $added_link = "<br><a href="https://google.com">Go to google</a>";
        
        $new_excerpt = $search_excerpt . $added_link;
        
        return $new_excerpt;
        
    }
    add_filter( 'the_excerpt', 'exceprt_link' );
    
} 
0
webdev1995 1 month 2021-06-17T14:48:38-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse