How do you change the theme location?

To change the upload directory I have to do this:

define ( "upload", "<new upload location>" );

How can you change the themes location? I like to create a folder themes in the root directory.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You can register additional directory or directories with themes by using register_theme_directory() function, that accepts filesystem path to folder.

Note that this isn’t typical and even while core handles it mostly fine, third party code in themes and plugins might not.

Method 2

You have to change the path and the URL to make sure themes work. I am using the following MU-Plugin in one of my local setups:

<?php
/* Plugin Name: Local Theme Roots */

if ( 'single.wp' === $_SERVER['HTTP_HOST'] )
    return;

add_filter( 'theme_root_uri', 't5_switch_theme_root' );
add_filter( 'theme_root',     't5_switch_theme_root' );

/**
 * Create a custom theme directory.
 *
 * @wp-hook theme_root
 * @wp-hook theme_root_uri
 * @author  Thomas Scholz, http://toscho.de
 * @param   string $in URL or path
 * @return  string
 */
function t5_switch_theme_root( $in )
{
    // local multi-sites end with 'mu.wp'. Example: t5.mu.wp.
    if ( 0 !== stripos( strrev( $_SERVER['HTTP_HOST'] ), 'pw.um' ) )
    {
        return $in;
    }


    if ( 'theme_root_uri' === current_filter() )
    {
        return "http://themes.wp";
    }

    // If we made it so far we are in the 'theme_root' filter.
    $new_root = dirname( dirname( __DIR__ ) ) . '/wp-themes';
    register_theme_directory( $new_root );
    return $new_root;
}

Be aware automatic theme upgrades will not work now due to a bug in the upgrader. I have fixed that and submitted a patch, but until 3.6 comes out you have to run upgrades separately.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x