Skip Navigation

[Resolved] Disabling new View wrapper div in Views >= 1.11

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here is that a new wrapper div has been added to views since the latest 1.11 update. This additional div is causing issues for some customers and they would like to know how to remove it.

Solution:

To resolve this issue you need to add the following code to your theme's functions.php file.

/**
 * Add ability to disable wrapper div around views by specifying a no-view-wrap=true shortcode attribute
 */
add_filter( 'wpv_filter_wpv_view_shortcode_output', 'thewebists_no_view_wrap', 5, 2 );
function thewebists_no_view_wrap( $out, $id ) {
    global $WP_Views;
    $view_shortcode_attributes = $WP_Views->view_shortcode_attributes;
    if($view_shortcode_attributes[count($view_shortcode_attributes)-1]["no-view-wrap"] == "true") {
        $start = strpos( $out, '' );
        if ( 
            $start !== false
            && strrpos( $out, '', $start ) !== false
            ) {
            $start = $start + strlen( '' );
        $out = substr( $out , $start );
        $end = strrpos( $out, '' );
        $out = substr( $out, 0, $end );
        }
    return $out;
    }
}
This support ticket is created 8 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 1.98 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 8 replies, has 7 voices.

Last updated by cliffC 8 years, 3 months ago.

Assisted by: Shane.

Author
Posts
#359402

Hi,

I'm facing problems with the new wrapper div that's being added around Views since v. 1.11.

I realise this question has been asked before, and I have found the snippet of code to display only the inner output of the views as answered here: https://toolset.com/forums/topic/nested-views-outputting-extra-divs-over-over-again/#post-347043

The problem is that the solution applies to all instances of a given view.

Can you help me adapt this solution to work based on a parameter passed in the shortcode so that I can selectively disable the wrapper div?

e.g.

[wpv-view name="my-view" disable-wrap="true"]

On a different note, are there plans to integrate this functionality into Views? I'd either expect the View to automatically render without the div if it's not using paging/filtering etc. or have the option to disable it (which can then force disable paging/filtering to ensure consistent behaviour).

FYI, this change has caused a lot of CSS/JQuery related issues on my sites. I've also had clients looking at the HTML source asking my what all the "ugly" code is for when there is not functionality on the page that requires it.

Regards,
Andy

#359433

Looks like I solved it. For the benefit of others, the code I've come up with (based on your other solution) is:

/**
 * Add ability to disable wrapper div around views by specifying a no-view-wrap=true shortcode attribute
 */
add_filter( 'wpv_filter_wpv_view_shortcode_output', 'thewebists_no_view_wrap', 5, 2 );
function thewebists_no_view_wrap( $out, $id ) {
    global $WP_Views;
    $view_shortcode_attributes = $WP_Views->view_shortcode_attributes;
    if($view_shortcode_attributes[count($view_shortcode_attributes)-1]["no-view-wrap"] == "true") {
        $start = strpos( $out, '<!-- wpv-loop-start -->' );
        if ( 
            $start !== false
            && strrpos( $out, '<!-- wpv-loop-end -->', $start ) !== false
            ) {
            $start = $start + strlen( '<!-- wpv-loop-start -->' );
        $out = substr( $out , $start );
        $end = strrpos( $out, '<!-- wpv-loop-end -->' );
        $out = substr( $out, 0, $end );
        }
    return $out;
    }
}

Admittedly, I'm not too happy with the string manipulation approach here.

Please let me know if there's a more reliable alternative to this function, and whether (when) this functionality will be included on the Toolset front-end.

Regards,
Andy

#359557

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Andrze,

Thank you for contacting our support forum.

I must apologize for the extensive delay in my response.

This has been something that many of our customers has been asking for a similar solution so this would definitely be a solution that our other customers can use.

However due to the complaints we have been getting about this our developers have decided to add a new option to our views plugin to remove this from the view output.

This feature will be implemented in one of our future releases.

So you need not to worry because a solution is on the way.

Thanks,
Shane

#359602

Great! Thanks.

#437993

Any news in this case?

#471857

Hi Shane

I see you promised to implement a feature in a future release for removing the wrapper div. We very much need this - when is it going to happen?

Thanks

Alex

#482790

Hello,
i'm curious about this wrapper also... i'm completely stuck by the wrapper divs... i'm displauing a grid of views... but also empty views take space because of the view wrapper. It has been a year since @shane-c mentioned this... any progress?

#520973

I am very unhappy that this is still a problem and that the documented workarounds, which have all been put forward by members of the Toolset Community, no longer seem to work

I just don't understand why On The Go can't give us a proper solution to disabling all this often unnecessary output...

#1140641

I also need to remove the wrapper around the loop items. I get why it's there and what it's used for. I still have an instance that requires its removal.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.