Shortcode showing in search result

Hi,

I have previously made some changes to the search function to add the ability to search by product code. But when the results are shown there is the sharing shortcode shown in the text. Please, can you take a look at this and let me know how to remove it.

If you click the link below you will see what I mean. Also, I have noticed that the breadcrumb has some weird question marks rather than “m100”.

Regards,

Mark

Hi There,

Please add this custom code under functions.php file locates in your child theme:

add_filter('the_excerpt', 'x_custom_excerpt');
function x_custom_excerpt( $content ){

	// Remove all shortcodes
	$content = strip_shortcodes( $content );

	return $content;
}

Let us know how it goes!

Thank you that has sorted the shortcode appearing in the search result. :grinning:

Is there any way of correcting the ?M100?, rather than “M100”, showing in the breadcrumb?

https://www.evernote.com/l/AHast-iL9wxIv6AIHHlEj1lwKhL8IlHopfEB/image.png

That most probably has something to do with character encoding in your setup. Please try to follow this guide. If that does not help, you will need to hire a developer to fix it because this is not an issue with X.

Thanks.

Ok thanks. I tried that and nothing happened so I guess I will just have to live with it.

You’re welcome.

I was previously given some code to by the X support team to enable searching via product code which was added to the functions.php. I am suspecting there is some issue within that which is now causing this issue.

I tried to add the code to this message but it got screwed up. Is there a way for me to add code to a message so that you can see it on this support forum software?

Hi there,

You can paste the code here and then select all of your code by dragging your mouse and click on preformatted text button (see screenshot)

Hope this helps!

Thanks

This was the code I was previously given to make it that I could search by SKU does this look correct or could this be causing the problem?

https://www.evernote.com/l/AHast-iL9wxIv6AIHHlEj1lwKhL8IlHopfEB/image.png

// search by sku
add_filter('posts_where', 'search_by_sku' );
function search_by_sku( $where )
{
  if( is_search() ) {
    global $wpdb;
    $query = get_search_query();
    $query = like_escape( $query );
    $where .=" OR {$wpdb->posts}.ID IN (SELECT IF({$wpdb->posts}.post_parent>0,{$wpdb->posts}.post_parent,{$wpdb->posts}.ID) FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->postmeta}.meta_key = '_sku' AND {$wpdb->postmeta}.meta_value LIKE '%$query%' AND {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id)";
    }
    return $where;
}

Hello There,

The code did not affected nor related to the breadcrumb. Do you have some modifications to the breadcrumbs? If you did modify it, please post your modification in your next reply.

If not, maybe you can re install the theme files. Some of the files may have been corrupted which is why this issue has surfaced.

Please let us know how it goes.

Hi,

Here is a bit of code in my functions.php which effects breadcrumbs

// Breadcrumbs Display Category Name
// =============================================================================

function get_breadcrumb_category( $cat ) {
   $post = get_post( $post->ID );
   $post_type = $post->post_type;
   $taxonomy = $cat;
   $f_categories = wp_get_post_terms( $post->ID, $taxonomy );
   $f_category = $f_categories[0];
   if ( $f_category->parent != 0 ) {
      $f_category_id    = $f_category->parent;
      $parent_array     = get_term_by('id', $f_category_id, $taxonomy, 'ARRAY_A');
      $f_category_name  = $parent_array["name"];
      $term_link        = get_term_link( $f_category_id, $taxonomy );
   } else {
      $f_category_id    = $f_category->term_id;
      $f_category_name  = $f_category->name;
      $term_link        = get_term_link( $f_category_id, $taxonomy );
   }
   if ( $f_categories && ! is_wp_error($f_categories) ) {
      return '<a href="' . $term_link . '">' . $f_category_name . '</a>';
   } else {
      return '';
   }
}
function x_breadcrumbs() {
    if ( x_get_option( 'x_breadcrumb_display', '1' ) ) {
      GLOBAL $post;
      $is_ltr         = ! is_rtl();
      $stack          = x_get_stack();
      $delimiter      = x_get_breadcrumb_delimiter();
      $home_text      = x_get_breadcrumb_home_text();
      $home_link      = home_url();
      $current_before = x_get_breadcrumb_current_before();
      $current_after  = x_get_breadcrumb_current_after();
      $page_title     = get_the_title();
      $blog_title     = get_the_title( get_option( 'page_for_posts', true ) );
      $post_parent    = $post->post_parent;
      
      if ( X_WOOCOMMERCE_IS_ACTIVE ) {
        $shop_url   = x_get_shop_link();
        $shop_title = x_get_option( 'x_' . $stack . '_shop_title', __( 'The Shop', '__x__' ) );
        $shop_link  = '<a href="'. $shop_url .'">' . $shop_title . '</a>';
      }
      echo '<div class="x-breadcrumbs"><a href="' . $home_link . '">' . $home_text . '</a>' . $delimiter;
        if ( is_home() ) {
          echo $current_before . $blog_title . $current_after;
        } elseif ( is_category() ) {
          $the_cat = get_category( get_query_var( 'cat' ), false );
          if ( $the_cat->parent != 0 ) echo '<a href="'.get_permalink(102).'">'.get_the_title(102) .'</a>';
          echo $current_before . single_cat_title( '', false ) . $current_after;
        } elseif ( x_is_product_category() ) {
          if ( $is_ltr ) {
            echo $shop_link . $delimiter . $current_before . single_cat_title( '', false ) . $current_after;
          } else {
            echo $current_before . single_cat_title( '', false ) . $current_after . $delimiter . $shop_link;
          }
        } elseif ( x_is_product_tag() ) {
          if ( $is_ltr ) {
            echo $shop_link . $delimiter . $current_before . single_tag_title( '', false ) . $current_after;
          } else {
            echo $current_before . single_tag_title( '', false ) . $current_after . $delimiter . $shop_link;
          }
        } elseif ( is_search() ) {
          echo $current_before . __( 'Search Results for ', '__x__' ) . 'ì' . get_search_query() . 'î' . $current_after;
        } elseif ( is_singular( 'post' ) ) {
          if ( get_option( 'page_for_posts' ) == is_front_page() ) {
          } else {
            if ( $is_ltr ) {
              $f_category = get_the_category();
              if ( $f_category[0]->parent != 0 ) {
                 $f_category_id = $f_category[0]->parent;
                 $f_category_name = get_cat_name( $f_category_id );
              } else {
                 $f_category_id = $f_category[0]->term_id;
                 $f_category_name = $f_category[0]->name;
              }
              echo '<a href="' . get_category_link( $f_category_id ) . '">' . $f_category_name . '</a>' . $delimiter . $current_before . $page_title . $current_after;
            } else {
              echo $current_before . $page_title . $current_after . $delimiter . '<a href="' . get_permalink( get_option( 'page_for_posts' ) ) . '">' . $blog_title . '</a>';
            }
          }
        } elseif ( x_is_portfolio() ) {
          echo $current_before . get_the_title() . $current_after;
        } elseif ( x_is_portfolio_item() ) {
          $link  = x_get_parent_portfolio_link();
          $title = x_get_parent_portfolio_title();
          if ( $v = get_breadcrumb_category('portfolio-category') ) {
            $portfolio_category = $delimiter . $v;
          } else {
            $portfolio_category = '';
          }
          if ( $is_ltr ) {
            echo '<a href="' . $link . '">' . $title . '</a>' . $portfolio_category . $delimiter . $current_before . $page_title . $current_after;
          } else {
            echo $current_before . $page_title . $current_after . $portfolio_category . $delimiter . '<a href="' . $link . '">' . $title . '</a>';
          }
        } elseif ( x_is_product() ) {
         if ( $v = get_breadcrumb_category('product_cat') ) {
           $product_category = $delimiter . $v;
         } else {
           $product_category = '';
         }
          if ( $is_ltr ) {
            echo $shop_link . $product_category . $delimiter . $current_before . $page_title . $current_after;
          } else {
            echo $current_before . $page_title . $current_after . $product_category . $delimiter . $shop_link;
          }
        } elseif ( x_is_buddypress() ) {
          if ( bp_is_group() ) {
            echo '<a href="' . bp_get_groups_directory_permalink() . '">' . x_get_option( 'x_buddypress_groups_title', __( 'Groups', '__x__' ) ) . '</a>' . $delimiter . $current_before . x_buddypress_get_the_title() . $current_after;
          } elseif ( bp_is_user() ) {
            echo '<a href="' . bp_get_members_directory_permalink() . '">' . x_get_option( 'x_buddypress_members_title', __( 'Members', '__x__' ) ) . '</a>' . $delimiter . $current_before . x_buddypress_get_the_title() . $current_after;
          } else {
            echo $current_before . x_buddypress_get_the_title() . $current_after;
          }
        } elseif ( x_is_bbpress() ) {
          remove_filter( 'bbp_no_breadcrumb', '__return_true' );
          if ( bbp_is_forum_archive() ) {
            echo $current_before . bbp_get_forum_archive_title() . $current_after;
          } else {
            echo bbp_get_breadcrumb();
          }
          add_filter( 'bbp_no_breadcrumb', '__return_true' );
        } elseif ( is_page() && ! $post_parent ) {
          echo $current_before . $page_title . $current_after;
        } elseif ( is_page() && $post_parent ) {
          $parent_id   = $post_parent;
          $breadcrumbs = array();
          if ( is_rtl() ) {
            echo $current_before . $page_title . $current_after . $delimiter;
          }
          while ( $parent_id ) {
            $page          = get_page( $parent_id );
            $breadcrumbs[] = '<a href="' . get_permalink( $page->ID ) . '">' . get_the_title( $page->ID ) . '</a>';
            $parent_id     = $page->post_parent;
          }
          if ( $is_ltr ) {
            $breadcrumbs = array_reverse( $breadcrumbs );
          }
          for ( $i = 0; $i < count( $breadcrumbs ); $i++ ) {
            echo $breadcrumbs[$i];
            if ( $i != count( $breadcrumbs ) -1 ) echo $delimiter;
          }
          if ( $is_ltr ) {
            echo $delimiter . $current_before . $page_title . $current_after;
          }
        } elseif ( is_tag() ) {
          echo $current_before . single_tag_title( '', false ) . $current_after;
        } elseif ( is_author() ) {
          GLOBAL $author;
          $userdata = get_userdata( $author );
          echo $current_before . __( 'Posts by ', '__x__' ) . 'ì' . $userdata->display_name . $current_after . 'î';
        } elseif ( is_404() ) {
          echo $current_before . __( '404 (Page Not Found)', '__x__' ) . $current_after;
        } elseif ( is_archive() ) {
          if ( x_is_shop() ) {
            echo $current_before . $shop_title . $current_after;
          } else {
            echo $current_before . __( 'Archives ', '__x__' ) . $current_after;
          }
        }
      echo '</div>';
    }

Hi,

Please change your code to this.

// Breadcrumbs Display Category Name
// =============================================================================

function get_breadcrumb_category( $cat ) {
   $post = get_post( $post->ID );
   $post_type = $post->post_type;
   $taxonomy = $cat;
   $f_categories = wp_get_post_terms( $post->ID, $taxonomy );
   $f_category = $f_categories[0];
   if ( $f_category->parent != 0 ) {
      $f_category_id    = $f_category->parent;
      $parent_array     = get_term_by('id', $f_category_id, $taxonomy, 'ARRAY_A');
      $f_category_name  = $parent_array["name"];
      $term_link        = get_term_link( $f_category_id, $taxonomy );
   } else {
      $f_category_id    = $f_category->term_id;
      $f_category_name  = $f_category->name;
      $term_link        = get_term_link( $f_category_id, $taxonomy );
   }
   if ( $f_categories && ! is_wp_error($f_categories) ) {
      return '<a href="' . $term_link . '">' . $f_category_name . '</a>';
   } else {
      return '';
   }
}
function x_breadcrumbs() {
    if ( x_get_option( 'x_breadcrumb_display', '1' ) ) {
      GLOBAL $post;
      $is_ltr         = ! is_rtl();
      $stack          = x_get_stack();
      $delimiter      = x_get_breadcrumb_delimiter();
      $home_text      = x_get_breadcrumb_home_text();
      $home_link      = home_url();
      $current_before = x_get_breadcrumb_current_before();
      $current_after  = x_get_breadcrumb_current_after();
      $page_title     = get_the_title();
      $blog_title     = get_the_title( get_option( 'page_for_posts', true ) );
      $post_parent    = $post->post_parent;
      
      if ( X_WOOCOMMERCE_IS_ACTIVE ) {
        $shop_url   = x_get_shop_link();
        $shop_title = x_get_option( 'x_' . $stack . '_shop_title', __( 'The Shop', '__x__' ) );
        $shop_link  = '<a href="'. $shop_url .'">' . $shop_title . '</a>';
      }
      echo '<div class="x-breadcrumbs"><a href="' . $home_link . '">' . $home_text . '</a>' . $delimiter;
        if ( is_home() ) {
          echo $current_before . $blog_title . $current_after;
        } elseif ( is_category() ) {
          $the_cat = get_category( get_query_var( 'cat' ), false );
          if ( $the_cat->parent != 0 ) echo '<a href="'.get_permalink(102).'">'.get_the_title(102) .'</a>';
          echo $current_before . single_cat_title( '', false ) . $current_after;
        } elseif ( x_is_product_category() ) {
          if ( $is_ltr ) {
            echo $shop_link . $delimiter . $current_before . single_cat_title( '', false ) . $current_after;
          } else {
            echo $current_before . single_cat_title( '', false ) . $current_after . $delimiter . $shop_link;
          }
        } elseif ( x_is_product_tag() ) {
          if ( $is_ltr ) {
            echo $shop_link . $delimiter . $current_before . single_tag_title( '', false ) . $current_after;
          } else {
            echo $current_before . single_tag_title( '', false ) . $current_after . $delimiter . $shop_link;
          }
        } elseif ( is_search() ) {
          echo $current_before . __( 'Search Results for ', '__x__' ) . '“' . get_search_query() . '”' . $current_after;
        } elseif ( is_singular( 'post' ) ) {
          if ( get_option( 'page_for_posts' ) == is_front_page() ) {
          } else {
            if ( $is_ltr ) {
              $f_category = get_the_category();
              if ( $f_category[0]->parent != 0 ) {
                 $f_category_id = $f_category[0]->parent;
                 $f_category_name = get_cat_name( $f_category_id );
              } else {
                 $f_category_id = $f_category[0]->term_id;
                 $f_category_name = $f_category[0]->name;
              }
              echo '<a href="' . get_category_link( $f_category_id ) . '">' . $f_category_name . '</a>' . $delimiter . $current_before . $page_title . $current_after;
            } else {
              echo $current_before . $page_title . $current_after . $delimiter . '<a href="' . get_permalink( get_option( 'page_for_posts' ) ) . '">' . $blog_title . '</a>';
            }
          }
        } elseif ( x_is_portfolio() ) {
          echo $current_before . get_the_title() . $current_after;
        } elseif ( x_is_portfolio_item() ) {
          $link  = x_get_parent_portfolio_link();
          $title = x_get_parent_portfolio_title();
          if ( $v = get_breadcrumb_category('portfolio-category') ) {
            $portfolio_category = $delimiter . $v;
          } else {
            $portfolio_category = '';
          }
          if ( $is_ltr ) {
            echo '<a href="' . $link . '">' . $title . '</a>' . $portfolio_category . $delimiter . $current_before . $page_title . $current_after;
          } else {
            echo $current_before . $page_title . $current_after . $portfolio_category . $delimiter . '<a href="' . $link . '">' . $title . '</a>';
          }
        } elseif ( x_is_product() ) {
         if ( $v = get_breadcrumb_category('product_cat') ) {
           $product_category = $delimiter . $v;
         } else {
           $product_category = '';
         }
          if ( $is_ltr ) {
            echo $shop_link . $product_category . $delimiter . $current_before . $page_title . $current_after;
          } else {
            echo $current_before . $page_title . $current_after . $product_category . $delimiter . $shop_link;
          }
        } elseif ( x_is_buddypress() ) {
          if ( bp_is_group() ) {
            echo '<a href="' . bp_get_groups_directory_permalink() . '">' . x_get_option( 'x_buddypress_groups_title', __( 'Groups', '__x__' ) ) . '</a>' . $delimiter . $current_before . x_buddypress_get_the_title() . $current_after;
          } elseif ( bp_is_user() ) {
            echo '<a href="' . bp_get_members_directory_permalink() . '">' . x_get_option( 'x_buddypress_members_title', __( 'Members', '__x__' ) ) . '</a>' . $delimiter . $current_before . x_buddypress_get_the_title() . $current_after;
          } else {
            echo $current_before . x_buddypress_get_the_title() . $current_after;
          }
        } elseif ( x_is_bbpress() ) {
          remove_filter( 'bbp_no_breadcrumb', '__return_true' );
          if ( bbp_is_forum_archive() ) {
            echo $current_before . bbp_get_forum_archive_title() . $current_after;
          } else {
            echo bbp_get_breadcrumb();
          }
          add_filter( 'bbp_no_breadcrumb', '__return_true' );
        } elseif ( is_page() && ! $post_parent ) {
          echo $current_before . $page_title . $current_after;
        } elseif ( is_page() && $post_parent ) {
          $parent_id   = $post_parent;
          $breadcrumbs = array();
          if ( is_rtl() ) {
            echo $current_before . $page_title . $current_after . $delimiter;
          }
          while ( $parent_id ) {
            $page          = get_page( $parent_id );
            $breadcrumbs[] = '<a href="' . get_permalink( $page->ID ) . '">' . get_the_title( $page->ID ) . '</a>';
            $parent_id     = $page->post_parent;
          }
          if ( $is_ltr ) {
            $breadcrumbs = array_reverse( $breadcrumbs );
          }
          for ( $i = 0; $i < count( $breadcrumbs ); $i++ ) {
            echo $breadcrumbs[$i];
            if ( $i != count( $breadcrumbs ) -1 ) echo $delimiter;
          }
          if ( $is_ltr ) {
            echo $delimiter . $current_before . $page_title . $current_after;
          }
        } elseif ( is_tag() ) {
          echo $current_before . single_tag_title( '', false ) . $current_after;
        } elseif ( is_author() ) {
          GLOBAL $author;
          $userdata = get_userdata( $author );
          echo $current_before . __( 'Posts by ', '__x__' ) . 'ì' . $userdata->display_name . $current_after . 'î';
        } elseif ( is_404() ) {
          echo $current_before . __( '404 (Page Not Found)', '__x__' ) . $current_after;
        } elseif ( is_archive() ) {
          if ( x_is_shop() ) {
            echo $current_before . $shop_title . $current_after;
          } else {
            echo $current_before . __( 'Archives ', '__x__' ) . $current_after;
          }
        }
      echo '</div>';
    }

Hope that helps

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.