Title: Date Specific Stylesheet
Last modified: August 20, 2016

---

# Date Specific Stylesheet

 *  Resolved [InHouse](https://wordpress.org/support/users/inhouse/)
 * (@inhouse)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/date-specific-stylesheet/)
 * Hello,
 * I’m trying to change some CSS based on the current month. I have 4 seasonal background
   images to change automatically when a certain date.
 * I found some code that works but I need to modify it. I’m not sure how to make
   this work for multiple months. This works if I only use one month but I can’t
   figure out how to enter more than one numeral at a time. Thanks for any help!
 *     ```
       if( date('m') == '9, 10, 11, 12, 1' ) { ?>
       <link rel="stylesheet" href="<?php bloginfo('stylesheet_directory'); ?>/football.css" type="text/css" media="screen" />
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [InHouse](https://wordpress.org/support/users/inhouse/)
 * (@inhouse)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/date-specific-stylesheet/#post-3023960)
 * 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!
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/date-specific-stylesheet/#post-3023979)
 * 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' );
       ```
   
 *  Thread Starter [InHouse](https://wordpress.org/support/users/inhouse/)
 * (@inhouse)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/date-specific-stylesheet/#post-3023992)
 * Ahh, that is perfect! Thanks [@esmi](https://wordpress.org/support/users/esmi/)
   I really appreciate the help. For anyone else stumbling on to this post, the 
   [body class](https://codex.wordpress.org/Function_Reference/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' );
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Date Specific Stylesheet’ is closed to new replies.

## Tags

 * [background](https://wordpress.org/support/topic-tag/background/)
 * [body](https://wordpress.org/support/topic-tag/body/)
 * [class](https://wordpress.org/support/topic-tag/class/)
 * [css](https://wordpress.org/support/topic-tag/css/)
 * [date](https://wordpress.org/support/topic-tag/date/)
 * [image](https://wordpress.org/support/topic-tag/image/)
 * [month](https://wordpress.org/support/topic-tag/month/)
 * [style](https://wordpress.org/support/topic-tag/style/)
 * [Stylesheet](https://wordpress.org/support/topic-tag/stylesheet/)
 * [time](https://wordpress.org/support/topic-tag/time/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [InHouse](https://wordpress.org/support/users/inhouse/)
 * Last activity: [13 years, 8 months ago](https://wordpress.org/support/topic/date-specific-stylesheet/#post-3023992)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
