Support » Fixing WordPress » How to enable shortcodes in excerpts?

  • Hi,

    I am trying for hours now to resolve the issude with shortcodes not showing in excerpts, exept in the slideshow area.

    Please, help, I have tried everything and nothing works

Viewing 7 replies - 1 through 7 (of 7 total)
  • the theme is Arras

    excerpts are generated from the content by a wordpress filter using the functions wp_trim_excerpt() located in /wp-includes/formatting.php (from line 1808) which uses the line $text = strip_shortcodes( $text );

    if this would not be done, there would be a chance that the content generates something ugly – as in the case of the [gallery] shortcode for instance which then shows a bunch of styles 🙁

    you might need to write your own filter function to replace wp_trim_excerpt() in which you could replace the above line of code with a line to include a ‘do_shortcode()’ part to execute the shortcode before shortening the content.

    this sounds more complicated that it is:

    in functions.php of your theme, add a line to remove the existing filter, a second line to add your new filter, and the new function itself which you can more or less simply copy from the ‘wp_trim_excerpt()’ code:

    remove_filter('get_the_excerpt', 'wp_trim_excerpt');
    add_filter('get_the_excerpt', 'wp_trim_excerpt_do_shortcode');
    function wp_trim_excerpt_do_shortcode($text) {
    	$raw_excerpt = $text;
    	if ( '' == $text ) {
    		$text = get_the_content('');
    		$text = do_shortcode( $text ); // CHANGED HERE
    		$text = apply_filters('the_content', $text);
    		$text = str_replace(']]>', ']]>', $text);
    		$text = strip_tags($text);
    		$excerpt_length = apply_filters('excerpt_length', 55);
    		$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
    		$words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
    		if ( count($words) > $excerpt_length ) {
    			$text = implode(' ', $words);
    			$text = $text . $excerpt_more;
    		} else {
    			$text = implode(' ', $words);
    	return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);

    this is all.

    hope it does what you expect 😉

    I suppose it has to have someting to do with Arras theme.

    I have shanged the display type for tapestry in Search/Archive pages and it seams only the Node Based display type shows the shortcodes, argh

    is the shortcode defined according to shortcode api ?

    or maybe as a filter of ‘the_content’ or so ?

    I’m using the “Get Custom Field Values” plugin for generating the shortcodes
    – this was downloaded on so I suppose it is valid?

    solved at least some of the issues – being completely ignorant of syntax, I tried to experiment.
    I have changed <?php echo get_the_excerpt() ?> to <?php the_excerpt() ?> and it works.

    In Croatia we say: even a blind hen get the (maize) kernel eventually

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to enable shortcodes in excerpts?’ is closed to new replies.