WordPress.org

Ready to get started?Download WordPress

Forums

Switching themes (2 posts)

  1. ayman1
    Member
    Posted 2 years ago #

    I'm trying to write a plugin to switch the current theme everyday. I have 17 themes I'd like to rotate, so I wrote the following in the plugin, but it does not seem to do the job. What am I missing?

    $theme = get_theme_of_today();
    
    update_option('current_theme', null);
    update_option('template', $theme['Template']);
    update_option('stylesheet', $theme['Stylesheet']);
    get_current_theme();   //updates current theme from template & stylesheet provided
    
    function get_theme_of_today() {
       $day = (int) date('z');
       $themes = get_themes();
       $i = $day % count($themes);
       return $themes[$i];
    }

    Thanks for any help,
    AA

  2. ayman1
    Member
    Posted 2 years ago #

    Turns out that, since 2.5.0, there is a function called switch_theme()! It's in wp-includes/theme.php:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    So, it looks like the main thing I was missing was the do_action() at the end. So, the code should be:

    $theme = get_theme_of_today();
    switch_themes($theme['Template'], $theme['Stylesheet']);
    function get_theme_of_today() {
       $day = (int) date('z');
       $themes = get_themes();
       $i = $day % count($themes);
       return $themes[$i];
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags