Ever since you introduced 'wrapper divs' to help pagination, they have caused us problems with more sophisticated applications of Views.
Now, I have had to upgrade a website from Views 1.10 to 2.4.0 because I can no longer justify not upgrading WordPress.
SO, I NEED TO DISABLE THE WRAPPER DIVS FROM VIEWS OUTPUT ON A GLOBAL BASIS.
I am unable to find a working solution here on the forums, and there is no mention in the documentation that I can find.
We raised this issue last year - https://toolset.com/forums/topic/when-will-you-add-the-option-to-remove-the-wrapper-div-around-each-view/ - and it has not stopped being a problem.
This solution does not work (Views output disappears completely):
https://toolset.com/forums/topic/disabling-new-view-wrapper-div-in-views-1-11/
I am not convinced this solution works, and it has to be set up for each View which is simply not practical:
https://toolset.com/forums/topic/views-not-working-after-installing-v1-11/
It must be possible to provide a global function to disable this markup, which causes us nothing but problems.
Your urgent assistance much appreciated.
The issue is also raised in this thread: https://toolset.com/forums/topic/problem-with-view-wrapper-div-override-after-views-1-12-upgrade/
I am not convinced this modified solution works any more either.
Adriano says this will be discussed with the developers but I suspect this didn't happen.
Nigel
Supporter
Languages:
English (English )
Spanish (Español )
Timezone:
Europe/London (GMT+01:00)
Hi Simon
The issue is on our roadmap and it will be implemented—an increasing number of clients want a clean output of Views in JSON format, for example—but I can't say when.
In the meantime you can add the following code which will strip the wrapper div from any View output (only the content between <!-- wpv-loop-start --> and <!-- wpv-loop-end --> in the Loop Output section will be rendered.
Note that functionality which depends on the wrapper (e.g. filters and pagination) will no longer work.
/**
* Naked Views output with no wrapper divs
*/
add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_naked_view_output', 5, 2 );
function prefix_naked_view_output( $out, $view_id ) {
if ( true ) { // add test for View ID if required
$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;
}
I just tested the code on a local site and it worked as expected, but let me know if you have problems with it.
And don't forget to backup before making such a large version change of Views.
That is working for me, thank you
Can I recommend that a note about this be added somewhere to the documentation?
For the benefit of other users, we have a version of this solution we implemented which only targets specific Views based on ID:
/**
* Naked Views output with no wrapper divs - SPECIFY WHICH VIEWS TO TARGET
*/
add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_naked_view_output', 5, 2 );
function prefix_naked_view_output( $out, $view_id ) {
$views_to_target = array(599,3948,3026,);// replace with comma separated list of View IDs
if ( in_array($view_id, $views_to_target)) { // add test for View ID
$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;
}