Преглед изворни кода

Skatepark: Add class to body if featured image exists

Sarah Norris пре 3 година
родитељ
комит
3071cdd468
1 измењених фајлова са 12 додато и 0 уклоњено
  1. 12 0
      skatepark/functions.php

+ 12 - 0
skatepark/functions.php

@@ -57,3 +57,15 @@ require get_stylesheet_directory() . '/inc/block-patterns.php';
  * Block Styles.
  * Block Styles.
  */
  */
 require get_stylesheet_directory() . '/inc/block-styles.php';
 require get_stylesheet_directory() . '/inc/block-styles.php';
+
+/**
+ * Add class to body if post/page has a featured image.
+ */
+function add_featured_image_class( $classes ) {    
+	global $post;
+	if ( isset ( $post->ID ) && get_the_post_thumbnail( $post->ID ) ) {
+		$classes[] = 'has-featured-image';
+	}
+	return $classes;
+}
+add_filter( 'body_class', 'add_featured_image_class' );