Skip to content

Instantly share code, notes, and snippets.

@jjeaton
Created February 11, 2015 13:26
Show Gist options
  • Save jjeaton/6a4b1886763086631473 to your computer and use it in GitHub Desktop.
Save jjeaton/6a4b1886763086631473 to your computer and use it in GitHub Desktop.
Switches the theme, only for the homepage. May not help if widgets/menus also need to be switched.
<?php
add_action( 'setup_theme', 'this_setup_theme' );
/**
* Sets a different theme on the homepage from the rest of the site.
*
* Just checks the REQUEST_URI. Works, but hasn't been tested thoroughly.
* Currently it will only change if the query string is also empty, but if there
* needs to be query strings (e.g. utm_campaign, etc.) that can be dropped.
*
* Code from https://github.com/Rarst/toolbar-theme-switcher
*
* @return void
*/
function this_setup_theme() {
// Hack to tell if we're on the homepage
if ( '/' === $_SERVER['REQUEST_URI'] && empty( $_SERVER['QUERY_STRING'] ) ) {
$theme = wp_get_theme( 'twentythirteen' ); // @todo: use theme slug for homepage here
add_filter( 'pre_option_template', array( $theme, 'get_template' ) );
add_filter( 'pre_option_stylesheet', array( $theme, 'get_stylesheet' ) );
add_filter( 'pre_option_stylesheet_root', array( $theme, 'get_theme_root' ) );
$parent = $theme->parent();
if ( empty( $parent ) ) {
add_filter( 'pre_option_template_root', array( $theme, 'get_theme_root' ) );
} else {
add_filter( 'pre_option_template_root', array( $parent, 'get_theme_root' ) );
}
add_filter( 'pre_option_current_theme', '__return_false' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment