run shortcode in excerpt of single custom post type

Hi because of the way my theme is set up, I need to run a shortcode inside the excerpt of a custom post type (services). This is the code I have so far...

function do_my_shortcode_in_excerpt($excerpt) {
    if ( 'services' == get_post_type() ) {
        return do_shortcode(wp_trim_words(get_the_content(), 55));
    }
}
add_filter('get_the_excerpt', 'do_my_shortcode_in_excerpt');

This works fine (I'll need to increase the 55) but it stops the excerpts appearing everywhere else. I only want this filter to run on excerpts associated with services - leaving other excerpts unaffected. Can anyone assist me?

Topic shortcode excerpt filters Wordpress

Category Web


You just forgot to return the excerpt for the other post types.

Try for example:

function do_my_shortcode_in_excerpt( $excerpt ) 
{
    if ( 'services' == get_post_type() )
        $excerpt = do_shortcode( wp_trim_words( get_the_content(), 55 ) );

    return $excerpt;    
}

add_filter( 'get_the_excerpt', 'do_my_shortcode_in_excerpt' );

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.