Skip to content

Instantly share code, notes, and snippets.

@wokamoto
Forked from hissy/hardcode_theme_switcher.php
Last active December 11, 2015 23:49
Show Gist options
  • Select an option

  • Save wokamoto/4679580 to your computer and use it in GitHub Desktop.

Select an option

Save wokamoto/4679580 to your computer and use it in GitHub Desktop.

Revisions

  1. wokamoto revised this gist Jan 31, 2013. 1 changed file with 19 additions and 7 deletions.
    26 changes: 19 additions & 7 deletions hardcode_theme_switcher.php
    Original file line number Diff line number Diff line change
    @@ -8,13 +8,25 @@

    function my_theme_switcher($theme){
    // yes, it's hardcoded!
    if ( $_SERVER['REQUEST_URI'] == '/about/' ) {
    $overrideTheme = wp_get_theme('twentyten');
    if ( $overrideTheme->exists() ) {
    return $overrideTheme['Template'];
    } else {
    return $theme;
    }
    switch (preg_replace('#^/([^/]+)/?.*$#', '$1', $_SERVER['REQUEST_URI'])) {
    case 'about':
    $overrideTheme = 'twentyten';
    break;
    case 'news':
    $overrideTheme = 'twentyeleven';
    break;
    case 'blog':
    $overrideTheme = 'twentytwelve';
    break;
    default:
    $overrideTheme = false;
    }

    if ( $overrideTheme ) {
    $overrideTheme = wp_get_theme($overrideTheme);
    return $overrideTheme->exists()
    ? $overrideTheme['Template']
    : $theme;
    }
    return $theme;
    }
  2. @hissy hissy created this gist Jan 16, 2013.
    23 changes: 23 additions & 0 deletions hardcode_theme_switcher.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    <?php
    /*
    Plugin Name: Hardcode theme switcher
    Plugin URI: http://ja.forums.wordpress.org/topic/13483
    Author: Takuro Hishikawa
    Version: 0.1
    */

    function my_theme_switcher($theme){
    // yes, it's hardcoded!
    if ( $_SERVER['REQUEST_URI'] == '/about/' ) {
    $overrideTheme = wp_get_theme('twentyten');
    if ( $overrideTheme->exists() ) {
    return $overrideTheme['Template'];
    } else {
    return $theme;
    }
    }
    return $theme;
    }

    add_filter('stylesheet', 'my_theme_switcher', 50);
    add_filter('template', 'my_theme_switcher', 50);