Fix: “Element style not allowed as child of element div in this context”

Please follow 2 steps below:

1. add this code to file functions.php of your active theme:

// Content Views Pro - Disable print inline CSS, will print it at footer
add_filter( 'pt_cv_inline_view_style', '__return_false' );

// Content Views Pro - Fix HTML validator issue "Element style not allowed as child of element body in this context"
add_filter( 'pt_cv_delayed_css', 'cvp_theme_delayed_css', 100, 1 );
function cvp_theme_delayed_css( $args ) {
	$args = str_replace( array( '<style type="text/css"', 'style>' ), array( '<div style="display:none" data-type="cvpcss"', 'div>' ), $args );
	return $args;
}

2. add this code to Custom JS field in Content Views >> Settings page:

$('[data-type="cvpcss"]').each(function(){var t=$(this).html(),e='<style type="text/css" class="cvpstyle">'+t+"</style>";$("head").append(e),$(this).remove()});

Best regards,

Scroll to Top