Support Forum

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Some suggestions (you might already have solutions for?) Reply To: Some suggestions (you might already have solutions for?)

#2909
Adam
Participant

Thanks Tom that works perfectly.

This is the code I ended up with for anyone with the same problem. Add as a code snippet and set a custom field on your post page with the name ‘wpsp_excerpt’ and the value as your custom excerpt and it will display for WP Show Posts. If nothing is set it will default to the excerpt length you have set.

if ( ! function_exists( 'wpsp_excerpt' ) ) {
	function wpsp_excerpt( $excerpt_length )
	{
		global $post;

		if ( get_post_meta( get_the_ID(), $key = 'wpsp_excerpt', $single = true ) ) {

	        $content = get_post_meta( get_the_ID(), $key = 'wpsp_excerpt', $single = true );

	    } else {

	        $content = wp_trim_words( get_the_content(), $excerpt_length, apply_filters( 'wpsp_ellipses', '...' ) );

	    }
			
			// Strip shortcodes from our content
		$content = strip_shortcodes( $content );
		
		// Strip URLs from our excerpt (oembeds etc..)
		$content = preg_replace( '~http(s)?://[^\s]*~i', '', $content );
		
		// Return our content
		echo $content;
	}
}