5

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.

2 Answers 2

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.

3

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.

4
  • Doesn't seem to work toscho. maybe im missing something Sep 6, 2014 at 12:40
  • @willow This seems to be broken as of WordPress 3.9.
    – fuxia
    Sep 6, 2014 at 13:22
  • Ok yea I thought I might have been doing something wrong. Your domain extensions with .wp threw me off at first thinking it was part of the code like "wp-". Sep 6, 2014 at 16:55
  • 1
    It's shoking that this is really the only "almost working" solution for custom theme directories. Sep 6, 2014 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.