Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #747281

    I am using woocommerce and woocommerce bookings.

    With bookings I am unable to use the advanced layout editor as it does not work with woo bookings.

    I needed to leverage shortcodes in the product info and they return on the search results page.

    I would like to strip short codes from products in search results.

    I saw this article,
    https://kriesi.at/support/topic/strip-shortcodes-in-searchresults/

    But the function does not filter for products and the second recommendation, removing excerpts, is not an option on product pages.

    Any ideas, thanks!

    • This topic was modified 7 years, 9 months ago by bowmandesign.
    #749134

    Hi bowmandesign!

    Thank you for using Enfold.

    Please add this filter in the functions.php file:

    function ava_remove_shortcode_from_excerpt($content) {
    	if(!is_search()) return;
    	$content = strip_shortcodes( $content );
    	return $content;
    }
    add_filter('the_excerpt', 'ava_remove_shortcode_from_excerpt');

    If this is not working, please post the url to the site so that we can inspect the search page.

    Cheers!
    Ismael

    #749447

    Your function does remove the shortcodes, unfortunately, it also removes the content between the short codes.

    Can it remove the shortcodes only and leave the content?

    Thanks!

    #749722

    Hey!

    What kind of shortcodes are you using? Please try the following filter:

    function ava_remove_shortcode_from_excerpt($content) {
    	if(!is_search()) return;
    	$pattern = get_shortcode_regex();
    	$shortcode = preg_match_all( '/'. $pattern .'/s', $content, $matches );
    	if(!empty($matches)) {
    		foreach($matches[2] as $match2) {
    			$content = str_replace('['.$match2.']', '', $content);
    			$content = str_replace('[/'.$match2.']', '', $content);
    		}
    	}
    	$content = strip_shortcodes($content);
    	return $content;
    }
    add_filter('the_excerpt', 'ava_remove_shortcode_from_excerpt');

    Regards,
    Ismael

    #749744

    Worked great! Thanks!

    I am using the Layout Elements 1/2 + 1/2 to achieve a 2 column layout for long text.

    Great Job!

    #750242

    Looks like the still show up in the mini predictive search drop down, do you have a function for that? Thanks a bunch.

    #750296

    Hi!

    Please add this filter to remove the shortcode in the ajax search.

    add_filter('avf_ajax_search_excerpt', 'avf_ajax_search_excerpt_mod', 10);
    function avf_ajax_search_excerpt_mod($excerpt) {
    	preg_match_all("^\[(.*?)\]^", $excerpt, $matches, PREG_PATTERN_ORDER);
    	$excerpt = str_replace($matches[0], '', $excerpt);
    	return $excerpt;
    }

    Cheers!
    Ismael

    #750574

    Thanks! Works great!

    #750595

    Hi!

    Happy we can help.
    Please feel free to let us know if we can do anything else for you by creating a new ticket.
    Consider to also rate Enfold at themeforest, it will really help us a lot!

    Thank you very much

    Regards,
    Basilis

Viewing 9 posts - 1 through 9 (of 9 total)
  • The topic ‘Strip short codes from products in search results’ is closed to new replies.