WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. davidmcc3
    Member
    Posted 1 year ago #

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

    http://wordpress.org/extend/plugins/column-shortcodes/

  2. Codepress
    Member
    Plugin Contributor

    Posted 1 year 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
    Member
    Posted 1 year ago #

    Hi.
    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

About this Topic

Tags

No tags yet.