Column Shortcodes
[resolved] Using plugin removes Excerpts (3 posts)

  1. davidmcc3
    Posted 3 years ago #

    When I put shortcodes into a post, the Excerpt disappears. Has this been mentioned before? Can it be fixed?


  2. Codepress
    Plugin Contributor

    Posted 3 years ago #

    This is the default way on how WordPress handles the excerpt. It will always strip out the shortcodes.

    I modified the excerpt function for you so you it will leave the shortcodes in place when using the excerpt. Just place this code in your functions.php:

     *  Trim the excerpt with shortcodes
    function wp_trim_excerpt_with_shortcodes($text = '')
    	$raw_excerpt = $text;
    	if ( '' == $text ) {
    		$text = get_the_content('');
    		$text = apply_filters('the_content', $text);
    		$text = str_replace(']]>', ']]>', $text);
    		$excerpt_length = apply_filters('excerpt_length', 55);
    		$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
    		$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
    	return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
    remove_filter( 'get_the_excerpt', 'wp_trim_excerpt'  );
    add_filter( 'get_the_excerpt', 'wp_trim_excerpt_with_shortcodes' );

    Let me know if this works for you.

  3. davidmcc3
    Posted 3 years ago #

    Thanks for the code - not very confident with PHP, but will give it a try.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Column Shortcodes
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.