-
AuthorPosts
-
February 15, 2017 at 6:27 am #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, 10 months ago by bowmandesign.
February 20, 2017 at 5:37 am #749134Hi 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!
IsmaelFebruary 20, 2017 at 4:26 pm #749447Your 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!
February 21, 2017 at 6:06 am #749722Hey!
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,
IsmaelFebruary 21, 2017 at 6:53 am #749744Worked great! Thanks!
I am using the Layout Elements 1/2 + 1/2 to achieve a 2 column layout for long text.
Great Job!
February 22, 2017 at 4:00 am #750242Looks like the still show up in the mini predictive search drop down, do you have a function for that? Thanks a bunch.
February 22, 2017 at 7:41 am #750296Hi!
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!
IsmaelFebruary 22, 2017 at 6:15 pm #750574Thanks! Works great!
February 22, 2017 at 6:51 pm #750595Hi!
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 -
AuthorPosts
- The topic ‘Strip short codes from products in search results’ is closed to new replies.