I also thought about trying to add the current month to the body class but I wasn’t as successful finding code that would achieve this. If the body had the current month as a class I could target it with CSS. I think that method would be cleaner but I’ll take what I can get!
I think you’re pretty close. Not sure how you want to break the months up, so I’m assuming 4 images = spring, summer, autumn and winter, yes? Try adding the following to your theme’s functions.php file:
// Add special body classes based on season
if (!function_exists( 'season_body_class' ) ) :
function season_body_class($classes) {
if( date( 'm' ) == '12' || date( 'm' ) == '14' || date( 'm' ) == '2' ) $classes[] = 'winter';
elseif( date( 'm' ) == '3' || date( 'm' ) == '4' || date( 'm' ) == '5' ) $classes[] = 'spring';
elseif( date( 'm' ) == '6' || date( 'm' ) == '7' || date( 'm' ) == '8' ) $classes[] = 'summer';
elseif( date( 'm' ) == '9' || date( 'm' ) == '10' || date( 'm' ) == '11' ) $classes[] = 'autumn';
else $classes[] = 'unknown';
return $classes;
}
endif;
add_filter('body_class', 'season_body_class' );
Ahh, that is perfect! Thanks @esmi I really appreciate the help. For anyone else stumbling on to this post, the body class is also required for this to work.
<body <?php body_class($class); ?>>
// Add special body classes based on season
if (!function_exists( 'season_body_class' ) ) :
function season_body_class($classes) {
if( date( 'm' ) == '2' || date( 'm' ) == '3' || date( 'm' ) == '4' ) $classes[] = 'basketball';
elseif( date( 'm' ) == '5' || date( 'm' ) == '6' || date( 'm' ) == '7' || date( 'm' ) == '8' ) $classes[] = 'baseball';
elseif( date( 'm' ) == '9' || date( 'm' ) == '10' || date( 'm' ) == '11' || date( 'm' ) == '12' || date( 'm' ) == '1' ) $classes[] = 'football';
else $classes[] = '';
return $classes;
}
endif;
add_filter('body_class', 'season_body_class' );