Tagged: shortcode
- This topic has 3 replies, 2 voices, and was last updated 5 years, 5 months ago by Skandha.
-
AuthorPosts
-
October 11, 2018 at 7:28 pm #156569ebetechParticipant
I have created some custom shortcodes that displays an event’s date or location. The shortcodes work great with no errors. Problem is when you use the site’s search tool, the results do not display the shortcode’s content. All results are Pages, not Posts.
=== Example 1 ===
(Shortcode for Event Date = SATURDAY, AUGUST 4th) Page Displays: SATURDAY, AUGUST 4th 3:00 PM – 6:00 PM Home Arts Results Excerpt Displays: 3:00 PM – 6:00 PM Home Arts
=== END Example 1 ===
=== Example 2 ===
(Shortcode for Event Location = GENERAL PARKING) Page Displays: GENERAL PARKING - Express Train Results Excerpt Displays: - Express Train
=== END Example 2 ===
I tried adding the following — per link https://catchthemes.com/support-forum/topic/text-within-shortcodes-removed-from-front-page-excerpts/
add_filter( 'the_excerpt', 'shortcode_unautop'); add_filter( 'the_excerpt', 'do_shortcode');
But did not work.
What can I do to resolve this issue?
Thanks!
October 12, 2018 at 1:52 am #156593SkandhaParticipant@ebetech: Can you please post in your site URL so that I can look into the issue.
Kind Regards,
SkandhaOctober 15, 2018 at 1:39 pm #156812ebetechParticipantNever mind. After some research, I found the solution. It appears to be a WordPress core design. To display the shortcode content in results, add the following to your functions.php:
//Replace wp_trim_excerpt with a commented out strip_shortcodes() function improved_trim_excerpt($text) { $raw_excerpt = $text; if ( '' == $text ) { $text = get_the_content(''); //$text = strip_shortcodes( $text ); $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('improved_trim_excerpt', $text, $raw_excerpt); } remove_filter('get_the_excerpt', 'wp_trim_excerpt'); add_filter('get_the_excerpt', 'improved_trim_excerpt');
Thanks for the quick reply. Awesome theme. Awesome support.
October 19, 2018 at 12:41 am #157095 -
AuthorPosts
- The topic ‘Search Results not displaying Shortcode content’ is closed to new replies.