Change CSS according to Date (4 posts)

  1. Connor Crosby
    Posted 5 years ago #

    Hello! I am making a WordPress theme that will change its colors and graphics according to the date. For example, if it is December 25th, Christmas, it will change to Christmas colors and Christmas graphics.

    So, I figured I can change the CSS file according to the date. However, I don't want to manually change it, I would like PHP or something to change it for me. How can I achieve this?

    For example, PHP realizes its December 25th and adds a stylesheet link to css/christmas.css. Then on December 26th it removes it so it uses the default css. Thank you very much, I highly appreciate it.

  2. Michael
    Forum Moderator
    Posted 5 years ago #

    for instance, in header.php, after the line with:
    <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />

    you could add this kind of code:

    if( date('d m') == '25 12' ) { ?>
    <link rel="stylesheet" href="<?php bloginfo('stylesheet_directory'); ?>/css/christmas.php" type="text/css" media="screen" />
    <?php } ?>



  3. Connor Crosby
    Posted 5 years ago #

    Awesome! I will test this and let you know if it works or not.

  4. Connor Crosby
    Posted 5 years ago #

    Yes it works! Thank you so much!!

Topic Closed

This topic has been closed to new replies.

About this Topic