WordPress.org

Ready to get started?Download WordPress

Forums

Change CSS according to Date (4 posts)

  1. Connor Crosby
    Member
    Posted 3 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. alchymyth
    The Sweeper & Moderator
    Posted 3 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:

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

    http://php.net/manual/en/function.date.php

    untested

  3. Connor Crosby
    Member
    Posted 3 years ago #

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

  4. Connor Crosby
    Member
    Posted 3 years ago #

    Yes it works! Thank you so much!!

Topic Closed

This topic has been closed to new replies.

About this Topic