ThemeShaper Forums » Thematic


Shortcode content not showing up in search results

(7 posts)
  • Started 10 years ago by kfrank
  • Latest reply from ScottNix
  • This topic is not resolved
  1. kfrank

    I am using shortcodes on pages to make it easy for my client to edit the content is there a reason that shortcode content(the text between the shortcode tags) does not show up in the search results, excerpted like the posts do? For instance I am using something like:

    [member-info team="mets" number="33" position="pitcher"]
    Lorem ipsum dolor sit amet, abbas, et dolore minim quibus opto iustum augue, blandit      nunc scisco, letalis consequat consectetuer iusto. Wisi, brevitas tum sed esca esse facilisi in, turpis virtus.

    Is there any way that I can get my shortcode content(excerpted like my posts) to show up in my search results?

    I have created a child theme from the Thematic framework.

    Thanks for any help on this

    Posted 10 years ago #
  2. middlesister

    I'm not sure I follow you in what you want to happen vs what is happening.
    Do you have the shortcodes on wordpress Pages, and if so are there more than one shortcode per page?
    Is the other content from the pages showing up in the search results, and just the shortcode content somehow missing?
    Or is it so that you want each shortcode content to be a separate search result?

    There is a plugin called search everything ( but I wonder if that is the issue here. To wordpress, the content in between shortcodes are not a distinguished piece of information that can get excerpted like posts. You would be better suited to use a custom post type for that. The text in between the codes should be searchable though, as part of the page/post they are in.

    Posted 10 years ago #
  3. I happened to be playing with some content styling shortcodes. You are correct in that page content held within a shortcode won't show on search.

    An option to get around it is to actually add an excerpt to the page,

    I wasn't able to figure out a solution to get them to show, someone has probably gone through this process before, but I couldn't find it. I hate posting to examples which won't be around forever, but here is an example of the problem. one page has a excerpt, one page does not, and one post does not. Looks like it effects pages and posts without excerpts.

    Posted 10 years ago #
  4. middlesister

    This is interesting.
    The reason might be because shortcodes are processed with filters on the_content and that the_excerpt does not apply that filter.
    You could try adding that filter to excerpts as well. The priority seems to be important, try using the same number as for the_content and change it if it doesn't work.

    add_filter('the_excerpt', 'do_shortcode', 11);

    Posted 10 years ago #
  5. Tested the above code you provided middlesister. This allows you to use the shortcodes in the excerpt, which is good to know, but still requires adding manual excerpts (with or without shortcodes) to posts and pages to get them to show text on search.

    Just adding the code won't "show" the text hidden between shortcodes for the search function. The search is "finding" the text in the shortcodes, just not outputting the text to the search preview (it grabs what is not held in shortcodes), hope that makes a little sense.

    I will keep looking, surely this is a problem for a lot of people.

    Posted 10 years ago #
  6. middlesister

    Aha I see. So, the_excerpt filter is only working on the manually written excerpts, while search results are showing the automatically generated ones?
    Then I think I know where the culprit is: wp_trim_excerpt() -
    It uses strip_shortcodes() on the text before trimming it to 55 characters and adding the […] and so on.

    Excerpts can be annoying at times to get to where you want them. Helgatheviking made a nice thread at

    You could maybe use her technique of replacing wp_trim_excerpt with your own version, commenting out the ´strip_shortcodes()` part:

    //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 ) {
    			$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');

    You might also need to add
    $text = do_shortcode($text);
    in order to make sure the shortcodes are actually parsed and not just displayed.

    Posted 10 years ago #
  7. The solution above to comment out the strip_shortcodes above works great.

    On a side note, if you add excerpts functionality to "pages" through functions php (, and then remove it. The excerpts which you manually added to pages will still show, they have to be manually removed also.

    Thanks kfrank for notifying me of a problem I was eventually going to run into, and thanks middlesister for the solution.

    Posted 10 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.