Tagged: shortcode, Shortcodes
-
AuthorPosts
-
September 3, 2014 at 8:22 pm #313086
I need a way to remove (not just hide) a specific shortcode (av_slideshow_accordion) and its content from the frontend in a child theme..
Eg.function shortcode_cleaner() { remove_shortcode( 'av_slideshow_accordion' ); add_shortcode( 'av_slideshow_accordion', 'mobile_remove_shortcode' ); } add_action( 'after_theme_setup', 'shortcode_cleaner' ); function 'mobile_remove_shortcode(){ return ''; }
Won’t work when added to my functions.php .. did i get the shortcode name wrong or is it just impossible? ..any suggestions?
fyi: My goal is to reduce the size and loading time on mobile devices whenever possible and the accordion slideshow is just a waste bytes and space on smartphones.. Therefore I’ll let wp load a different child theme on those devices than on desktops..
thanks in advance! :)best regards
BenjaminSeptember 4, 2014 at 11:03 pm #313634Hi bboehm86!
Removing the shortcode would make the output look like plain text, It wouldn’t hide it on mobile.
Cheers!
DevinSeptember 5, 2014 at 9:45 am #313875Hi Devin,
well that would be the case for just
strip_shortcodes()
anyhow i used the wrong hook its now worikng/** * REMOVE Shortcodes */ if ( ! function_exists( 'remove_accordion_shortcode' ) ) { function remove_accordion_shortcode(){ return ""; } } if ( ! function_exists( 'shortcode_cleaner_accordion' ) ) { function shortcode_cleaner_accordion() { remove_shortcode( 'av_slideshow_accordion' ); add_shortcode( 'av_slideshow_accordion', 'remove_accordion_shortcode' ); } } add_action( 'wp_loaded', 'shortcode_cleaner_accordion' );
BUT afterwards the section divs (from the prealso were gone.. so i put them back into the shortcode..
/** * REMOVE Shortcodes */ if ( ! function_exists( 'remove_accordion_shortcode' ) ) { function remove_accordion_shortcode(){ $output .= " </div>"; // <!-- CLOSE entry-content-wrapper --> $output .= " </div>"; // <!-- CLOSE post-entry --> $output .= " </div>"; // <!-- close content main div --> $output .= " </div>"; // <!-- CLOSE container --> $output .= " </div>"; // <!-- CLOSE avia-sectio --> $output .= " <div class='main_color container_wrap fullsize'>"; // <!-- new section --> $output .= " <div class='container'>"; $output .= " <div class='template-page content twelve alpha units'>"; $output .= " <div class='post-entry post-entry-type-page post-entry-2'>"; $output .= " <div class='entry-content-wrapper clearfix'>"; return $output; } } if ( ! function_exists( 'shortcode_cleaner_accordion' ) ) { function shortcode_cleaner_accordion() { remove_shortcode( 'av_slideshow_accordion' ); add_shortcode( 'av_slideshow_accordion', 'remove_accordion_shortcode' ); } } add_action( 'wp_loaded', 'shortcode_cleaner_accordion' );
This fixed the missing divs on “old” accordion position.. BUT the closing divs of a colorsection went missing to.. but i got no clue why.. any idea?
September 5, 2014 at 11:08 am #313927Hey!
Because the color section and the accordion are fullwidth elements. If the accordion shortcode is used directly after the color section the “fullwidth” element divs are added after the accordion and not after the color section. I recommend to add a hr element (or any other non fullwidth element) between the accordion and the color section to solve this issue.
Best regards,
PeterSeptember 5, 2014 at 12:23 pm #313968first of all thanks for teh support guys..
My bad, i was a bit unclear.. the additional hr element worked just as adding the closing and opening divs..to be more accurat.. my problem wasnt that missing part but the missing of the closing divs form another color section element further down the page.. eg:
- header
- stuff
- color section
- accordion [removed]
- stuff [missing before, but solved]
- another color section [missing ending divs]
- masonry gallery [because of the missing ending div rendered inside the color section]
- google maps [same here]
- footer [same here]
so by removing the shortcode i threw out the endings for“fullwidth” element divs i guess.. any posibillity to get them back?
September 10, 2014 at 2:03 pm #316553Hey!
I’ll tag the topic for Peter and Kriesi if either want to dig in here but in general its far out of the scope of what we typically cover via support.
Cheers!
DevinSeptember 10, 2014 at 4:54 pm #316741Hey!
I didn’t test it but you can try to rewrite the remove_accordion_shortcode() function. In wp-content/themes/enfold/config-templatebuilder/avia-shortcodes/slideshow_accordion.php Kriesi uses a more complex version of this code:
$params = array(); $params['open_structure'] = false; $params['close'] = false; $output .= avia_new_section($params); $output .= $slide_html; $output .= "</div>"; //close section
$slide_html contains the slide/accordion data. $params[‘close’] may contain the value “true” if no fullwidth element is used after the accordion section.
Best regards,
Peter -
AuthorPosts
- You must be logged in to reply to this topic.