Using Shortcode in WordPress Post Excerpts

Shortcodes were introduced in WP version 2.5 primarily for use in post content. They were not meant for post excerpts nevertheless you can easily add the shortcode capability to your post’s excerpts.

To add the shortcode functionality to WordPress excerpts , hook your custom function to ‘get_the_excerpt’ filter in following way:

add_filter('get_the_excerpt', 'shortCode_enabled_excerpts');
function shortCode_enabled_excerpts($output){
    if(has_excerpt()){
        $output =  do_shortcode( $output );
    }
    return $output;
}

 

The above code allows you to add your custom shortcodes into post excerpts. The code will work with all those excerpts which are manually added to posts.