Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9206387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:09:52+00:00 2026-06-18T00:09:52+00:00

I developed a website with blog using wordpress. After I had my theme ready

  • 0

I developed a website with blog using wordpress. After I had my theme ready the website owner asked me to use other theme which he bought only for the website’s blog.

How can I initialize this second theme without setting it as website theme on the options table?

I could do it defining the constant TEMPLATEPATH in wp-includes/default_constants.php

function 'wp_templating_constants':
define('TEMPLATEPATH', get_theme_root() . '/theme-name');

And setting filters for:

pre_option_template, template, pre_option_current_theme, stylesheet_directory_uri, stylesheet_directory in the functions.php of the theme.

But of course, I want to do it dynamically after knowing if the user is or is not on a blog page. Does anyone have any idea how to do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:09:53+00:00Added an answer on June 18, 2026 at 12:09 am

    Here is the code for a plugin to set a theme to a list of categories which is not the theme defined on the database.

    new SetTheme('[THEME_NAME]', array('[CAT_NAME]', [CAT_ID], [CAT_OBJECT]));
    
    class SetTheme {
        private $theme_name = '';
        private $categories = array();
    
        public function __construct($theme_name, $categories) {
            // define original theme location for any reason
            define('ORIGTEMPLATEPATH', get_template_directory());
            define('ORIGTEMPLATEURI', get_template_directory_uri());
    
            // init class parameters
            $this->theme_name = $theme_name;
    
            foreach ($categories as $cat) {
                if (is_string($cat))
                    $cat = get_category_by_slug($cat);
    
                $category = get_category($cat);
                $this->categories[$category->term_id] = $category;
            }
    
            // apply action to setup the new theme only on action 'setup_theme'
            // because some functions are not yet loaded before this action
            add_action('setup_theme', array($this, 'setup_theme'));
        }
    
        public function setup_theme() {
            // if the current post or category is listed, apply the new theme to be initialized
            if ($this->is_category_theme())
                $this->set_theme();
        }
    
        private function is_category_theme() {
            // get category from current permalink
            // and check if is listed to apply the new theme
            $current_cat = get_category_by_path($_SERVER["HTTP_HOST"] . $_SERVER['REQUEST_URI'], false);
            if (isset($this->categories[$current_cat->term_id])) return true;
    
            // get post from current permalink
            // and check if it belongs to any of listed categories
            $current_post = url_to_postid($_SERVER['REQUEST_URI']);
            $post_categories = wp_get_post_categories($current_post);
            foreach ($post_categories as $cat_id)
                if (isset($this->categories[$cat_id])) return true;
    
            return false;
        }
    
        private function set_theme() {
            // apply the filters to return the new theme's name
            add_filter('template', array($this, 'template_name'));
            add_filter('stylesheet', array($this, 'template_name'));
        }
    
        public function template_name() {
            // return new name
            return $this->theme_name;
        }
    }
    

    The parameters of the class are the theme name and an array of categories (ids, slugs or category objects).

    Of course, this is what i need, probably for other themes it will be required other filters in the function ‘set_theme’.

    It needs to be a plugin because plugins are loaded before the theme and even before WP class.

    With this plugin the original plugin will never be called (at least on my case).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed this website thereelthing.com.sg/ how ever after 3 week which i have
I have developed a website using visual studio 2008. Which uses active index to
I've developed a website using RefineryCMS, and now the client have asked for a
I developed a website using EF 4.1 code first,Mvc3 ,Sql Sever 2008 r2, and
I have developed a website using Razor (Microsoft WebMatrix) and now I want to
I have a website developed in ASP.NET and VB.NET which has a place for
i have developed my website in VS2010. is there any tool freely available which
I had developed one website purely in HTML .I have my form with fields
I am having an issue with a website developed using ASP.Net/C# sometimes taking all
My ruby website is developed and hosted on heroku server(mysite.com).Now i developed a wordpress

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.