Create a gist now

Instantly share code, notes, and snippets.

WordPress tiny plugin - Switch theme on certain pages
<?php
/**
* @package One_Fix_Switch_Theme
* @version 1.0
*/
/*
Plugin Name: One Fix Switch Theme
Plugin URI: https://www.1fix.io
Description: Switch theme on certain pages.
Author: Yoren Chang
Version: 1.0
Author URI: https://www.1fix.io
*/
function one_fix_switch_theme() {
add_filter( 'stylesheet', 'one_fix_stylesheet' );
add_filter( 'template', 'one_fix_template' );
}
add_action( 'setup_theme', 'one_fix_switch_theme' );
function one_fix_stylesheet( $current_theme ) {
$uri = explode( '/', $_SERVER['REQUEST_URI'] );
if ( in_array( $uri[1], array( 'slug-a', 'slug-b', 'slug-c' ) ) ) {
return 'twentythirteen-child';
} else {
return $current_theme;
}
}
function one_fix_template( $current_theme ) {
$uri = explode( '/', $_SERVER['REQUEST_URI'] );
if ( in_array( $uri[1], array( 'slug-a', 'slug-b', 'slug-c' ) ) ) {
return 'twentythirteen';
} else {
return $current_theme;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment