When vc-element first pos, add Class to body
Wenn ein bestimmtes VC-Element an erster Stelle ausgegeben wird, kann mit dieser Funktion eine Klasse zum Body hinzugefügt werden:
/**
* Add custom classes to body
*
* @param $classes array
* @return array
*/
function spl_add_bodyclasses( $classes ) {
global $post;
// Check if vc_bgimage element is the first in content
preg_match_all( '/'. get_shortcode_regex() .'/s', $post->post_content, $matches );
if( strpos($matches[0][0], '[vc_bgimage' ) !== false || is_404() || strpos($matches[0][0], '[vc_contactmap' ) !== false || strpos($matches[0][0], '[vc_slider' ) !== false ) {
array_push( $classes, 'main-content-no-spacingtop' );
}
return $classes;
}
add_filter( 'body_class', 'spl_add_bodyclasses' );