Skip Navigation

[Resolved] Need to remove unwanted markup from wpv-view

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

Problem:
The issue here is that Views is generated some additional markup around its content output and the customer wanted to remove this.

Solution:

You can use the code below to remove the extra div wrappers around your view.

add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 );
 
function prefix_clean_view_output( $out, $id ) {
    if ( $id == '375' ) {
        $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;
}

Replace the id 375 with the ID of your view.

This support ticket is created 7 years 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.83 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)

This topic contains 3 replies, has 2 voices.

Last updated by chrisH-10 7 years ago.

Assisted by: Shane.

Author
Posts
#515442

This is somewhat related to the below ticket, please tell me you have fixed this!
https://toolset.com/forums/topic/how-to-remove-data-pagination-code/

I created a view that I am emitting using do_shortcode. Unfortunately the output I specified is being wrapped in

<div id="wpv-view-layout-54-TCPID4" class="js-wpv-view-layout js-wpv-layout-responsive js-wpv-view-layout-54-TCPID4" data-viewnumber="54-TCPID4" data-pagination="{"id":"54","base_permalink":"/?wpv_view_count=54-TCPID4&wpv_paged=WPV_PAGE_NUM","query":"normal","type":"disabled","effect":"fade","duration":500,"speed":5,"pause_on_hover":"disabled","stop_rollover":"false","cache_pages":"enabled","preload_images":"enabled","preload_pages":"enabled","preload_reach":1,"spinner":"builtin","spinner_image":"<em><u>hidden link</u></em>","callback_next":"","manage_history":"enabled","has_controls_in_form":"disabled","infinite_tolerance":"0","max_pages":0,"page":1,"loop":{"type":"","name":"","data":[],"id":0}}" data-permalink="/?wpv_view_count=54-TCPID4">

I am using fullpage.js and this extra markup makes it unusable, never mind that it is worthless to me. Is there a flag to turn this off? Do I need to not use Views and write some PHP to achieve this?

#515445

Oh boy, I made the fullpage.js work by telling it to use the class "js-wpv-view-layout" that is unwanted, so that works now.

HOWEVER as the other ticket mentioned you inject unwanted JS as well!? That is generating script errors and blowing things up.

#515498

Shane
Supporter

Languages: English (English )

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

Hi Chris,

Thank you for contacting our support forum.

You can use the code below to remove the extra div wrappers around your view.

add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 );

function prefix_clean_view_output( $out, $id ) {
    if ( $id == '375' ) {
        $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;
}

Replace the id 375 with the ID of your view.

Thanks,
Shane

#515523

Brilliant!

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