Prevent GravityView from loading its CSS styles

If you want to apply your own CSS styles to your Views and stop bothering with the default styles loaded by GravityView then that can be easily achieved with the code snippet below:

add_action( 'wp_enqueue_scripts', 'gv_dequeue_main_css', 30 );
add_action( 'wp_print_scripts', 'gv_dequeue_main_css', 2 );

function gv_dequeue_main_css() {

	wp_dequeue_style( 'gravityview_default_style' );
	wp_dequeue_style( 'gravityview_style_default_table' );
	wp_dequeue_style( 'gravityview_style_default_list' );
	wp_dequeue_style( 'gravityview_style_datatables_table' );
	wp_dequeue_style( 'gv-dt_buttons_style' );
	wp_dequeue_style( 'gv-dt_fixedheader_style' );
	wp_dequeue_style( 'gv-dt_fixedcolumns_style' );
	wp_dequeue_style( 'gv-dt_responsive_style' );
	wp_dequeue_style( 'gv-dt_scroller_style' );
	wp_dequeue_style( 'gv-datatables-featured-entries' );
	wp_dequeue_style( 'gravityview_az_entry_filter' );
	wp_dequeue_style( 'gravityview-featured-entries' );
	wp_dequeue_style( 'gravityview-field-approval' );
	wp_dequeue_style( 'gravityview-field-approval-tippy' );
	wp_dequeue_style( 'gravityview_font' );
	wp_dequeue_style( 'gravityview_social_wordpress' );

}

However, if you wish to only load GravityView's styles on pages where the View is embedded, then use the function below by replacing the array containing the IDs of the pages below:

add_action( 'wp_enqueue_scripts', 'gv_dequeue_main_css', 30 );
add_action( 'wp_print_scripts', 'gv_dequeue_main_css', 2 );

function gv_dequeue_main_css() {
	
	global $post;
	$post_ids = array( 13 , 23 ); 

        // 13 and 23 are the IDs of the pages where the View is embedded. 
        // You can add more IDs as well by separating them with commas.

	if( in_array($post->ID, $post_ids) ) {

		wp_dequeue_style( 'gravityview_default_style' );
		wp_dequeue_style( 'gravityview_style_default_table' );
		wp_dequeue_style( 'gravityview_style_default_list' );
		wp_dequeue_style( 'gravityview_style_datatables_table' );
		wp_dequeue_style( 'gv-dt_buttons_style' );
		wp_dequeue_style( 'gv-dt_fixedheader_style' );
		wp_dequeue_style( 'gv-dt_fixedcolumns_style' );
		wp_dequeue_style( 'gv-dt_responsive_style' );
		wp_dequeue_style( 'gv-dt_scroller_style' );
		wp_dequeue_style( 'gv-datatables-featured-entries' );
		wp_dequeue_style( 'gravityview_az_entry_filter' );
		wp_dequeue_style( 'gravityview-featured-entries' );
		wp_dequeue_style( 'gravityview-field-approval' );
		wp_dequeue_style( 'gravityview-field-approval-tippy' );
		wp_dequeue_style( 'gravityview_font' );
		wp_dequeue_style( 'gravityview_social_wordpress' );

	}

}

Read here how to add these code samples to your website: Where to put code samples.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us