Support » Plugin: amr shortcode any widget » WP-Rocket and widgets for shortcode

  • Hi Anmari,
    Your plugin is great and works fine. We added three widgets to the Widgets for shortcodes sidebar and display the sidebar on the homepage via shortcode [do_widget_area widget_area=widgets_for_shortcodes].All displays fine! Great plugin, thanks.

    We just encountered a strange issue when we start using WP-Rocket on live server (WP-Rocket is looking into the issue also). After activating the Cache plugin WP-Rocket the Widget area <div id=”widgets_for_shortcodes” class=”amr-widget-area”> is shown without any <section> and <h2> tags of every single widget??
    Have you ever encountered a similar issue?

Viewing 2 replies - 1 through 2 (of 2 total)
  • I followed the code and in the file “amr-shortcode-any-widget.php” the function “amr_do_widget_area” calls the standard wordpress function dynamic_sidebar($widget_area); on line 77. When WP-Rocket plugin is deactivated it returns the full sidebar including <section> and <h2> tags. When WP-Rocket is activated it returns the sidebar without <section> and <h2> tags.

    I added following code to my functions.php which checks for the “widgets_for_shortcodes” sidebar and adds those tags dynamically.

    // Widget has <section> and <h2> removed somehow when WP-Rocket is active
    // With this function we add them dynamically again
    function widgets_for_shortcodes_widgets($params) {
    // Check if we are dealing with the correct sidebar with id=”widgets_for_shortcodes”
    if(isset($params[0][‘id’]) && $params[0][‘id’] == ‘widgets_for_shortcodes’){
    // Get and edit parameters
    $widget_id = $params[0][‘widget_id’];
    $widget_number = ‘-‘.$params[1][‘number’];
    $widget_class = rtrim($params[0][‘widget_id’],$widget_number);
    // Only replace empty values generated by Wp-Rocket
    if(empty($params[0][‘before_widget’])) {
    // Since widgets have class with or without widget_xxxxx we add both
    $params[0][‘before_widget’] = ‘<section id=”‘.$widget_id.'” class=”widget widget_’.$widget_class.’ ‘.$widget_class.’ “>’;
    if(empty($params[0][‘after_widget’])) {
    $params[0][‘after_widget’] = ‘</section>’;
    if(empty($params[0][‘before_title’])) {
    $params[0][‘before_title’] = ‘<h2 class=”widget-title”>’;
    if(empty($params[0][‘after_title’])) {
    $params[0][‘after_title’] = ‘</h2>’;
    return $params;

    Advise for Anmari: I tested styling the [do_widget] shortcode with wrap=section and title=h2 in the shortcode. And that works fine. The [do_widget_area] doesn’t apply these parameters. With the above function you could implement that functionality to the [do_widget_area] also?

    I know it is probably not your plugin’ fault Wp-Rocket doesn’t work together with the widgets_for_shortcodes sidebar. Maybe this helps others. Keep up the good work.

    Plugin Author anmari


    Hi Thanks for looking into it, and yes it does look like one could use the filter to add html styling. I’ll put it on the list.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WP-Rocket and widgets for shortcode’ is closed to new replies.