3rd party shortcodes not working in Posts Carousel

#1

I have an event program that provides shortcodes to populate the date/time of an event. It appears on the event page but doesn’t appear within the Posts Carousel.

Event - “Monthly Dinner”

    View Post Carousel-Date/time should show after "Join us Friday,": http://solanorepublicans.org/#events
    View whole post: http://solanorepublicans.org/events/monthly-dinner/

Date/time in red text is generated by shortcode.

Wasn’t sure if this was the theme, plugin, or wordpress the issue is with. Thanks!

#2

Hey Josh!

This might be because shortcodes and HTML don’t work with WP excerpt. Haven’t tried it myself by try adding the code below in your functions.php file and see if it helps. You can find your theme function file by going to Appearance > Editor > Theme Functions

add_filter('the_excerpt', 'do_shortcode');

Jun

#3

Hey Josh!

I just tested this and that single line of code will not work. It seems that this is a bit more complex than I originally thought but I found a solution someone posted here. Give it a try and let us know how it goes. You still add this in the functions.php file.

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 ) {
			array_pop($words);
			$text = implode(' ', $words);
			$text = $text . $excerpt_more;
		} else {
			$text = implode(' ', $words);
		}
	}
	return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
}

Jun

#4

That did the trick. Excellent. Thanks for digging into that one. Your 2nd post made the difference!

#5

Hey Josh!

Glad to hear it’s all sorted out now and thanks for taking the time to let us know. We appreciate it!

Have a nice day!

Jun

closed #6