Support » Fixing WordPress » How do you strip shortcodes from search pages?

  • Hi –
    The posts’ image shortcodes are appearing in my teaser on all archive pages. I’ve tried removing them by inserting this code into my functions.php:

    add_filter('the_content', 'strip_shortcodes');
    function remove_shortcode_from_index($content) {
      if ( is_search() ) {
        $content = strip_shortcodes( $content );
      return $content;

    However, this is only removing the shortcode from my actual posts (which removes the post’s image and caption), but does not remove the shortcode from all archive listings and search results.

    Can anyone help with this functions.php code? Or should I change the wp code in shortcodes.php?

    Thanks so much.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You are close! This is UNTESTED, but I think it will work (don’t know about the is_search() part):

    add_filter('the_excerpt', 'remove_shortcode_from_excerpt');
    function remove_shortcode_from_excerpt($excerpt) {
      if ( is_search() ) {
        $excerpt = strip_shortcodes( $excerpt );
      return $excerpt;

    Thanks vtxyzzy—I tried the code and it didn’t seem to work.

    The theme is built with ‘the_content’ showing all teasers so we have more flexibility with filters and styling. I think my big problem is the ‘is_search’ function, since it’s not working like the is_home is.

    Is there a different way to tell all search result pages to hide shortcodes?

    Reference to is_search is found on the wordpress doc here towards the lower half of the page.

    I don’t know about alternatives to is_search(). You might need to create a new topic for that question to get others to take a look.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How do you strip shortcodes from search pages?’ is closed to new replies.