Switch theme based on post ID

Below is a custom WordPress plugin that will switch to any theme based on the post ID. In this example, we’re switching post ID 1 to the Twenty Twenty Three theme.

ThemeSwitcher Pro works with custom code to easily create your own custom conditionals and manage via code. The plugin example code is located at https://github.com/WebDevStudios/theme-switcher-pro-add-ons. Copy the plugin code to your /plugins/ directory and customize away!

<?php
/**
 * Plugin Name: ThemeSwitcher Post Addon
 * Plugin URI: https://webdevstudios.com
 * Description: Switch to a custom theme if viewing a post with post ID.
 * Version: 0.1.0
 * Author URI: https://webdevstudios.com
 */
// phpcs:ignoreFile
/**
 * Example demonstrating how to add custom theme switching conditions.
 *
 * 1. Ensure that the ThemeSwitcher Pro plugin is installed and activated.
 * 2. Copy this file to your wp-content/plugins directory then activate it.
 * 3. Make sure that the themes referenced below are active in your install,
 *    (twentytwentyone, twentytwentytwo, and twentytwentythree)
 *    or change the example code so that it references your installed themes.
 * 4. Check out the themeswitcher-pro/inc/helper-functions.php file for helper functions.
 *
 * @return void
 */
function tsp_conditions() {
	if ( ! class_exists( 'TSP_Manager' ) ) {
		return;
	}

	/**
	 * Switch to a custom theme if viewing a post with post ID.
	 *
	 * @since 0.1.0
	 * @see   helper-functions.php
	 * @see   TSP_Manager
	 * @see   tsp-manager.php
	 */
	$post_id_from_settings = 1; // Change value to your desired post ID.

	TSP_Manager::register(
		'twentytwentythree', // Theme slug goes here.
		function () use ( $post_id_from_settings ) {
			return ( $post_id_from_settings === tsp_get_post_id() ) ? true : false;
		},
		1  // This Priorty must be set to 1.
	);
}
add_action( 'plugins_loaded', 'tsp_conditions', 100 ); // Use priority of 100.

What are your feelings
Updated on April 28, 2025