Using WordPress ‘register_theme_directory()’ PHP function

The register_theme_directory() WordPress PHP function registers a directory that contains themes.

Usage

register_theme_directory($directory);

Example:
Input:

register_theme_directory('/path/to/your/theme/directory');

Parameters

  • $directory (string) – The full filesystem path to a theme folder or a folder within WP_CONTENT_DIR.

More information

See WordPress Developer Resources: register_theme_directory()

Examples

Registering a plugin’s subdirectory as a theme folder

Explanation: The following code registers a subdirectory within a plugin as a theme folder. This is useful if you want to include custom themes with your plugin.

// Register a plugin's subdirectory as a theme folder
register_theme_directory(dirname(__FILE__) . '/themes');

Registering a custom theme folder outside of the default wp-content/themes folder

Explanation: The following code registers a custom theme folder that is located outside the default wp-content/themes folder.

// Register a custom theme folder
register_theme_directory('/path/to/your/custom/theme/folder');

Registering a theme folder inside a custom wp-content folder

Explanation: If you have a custom wp-content folder, you can use this code to register a theme folder within that custom folder.

// Register a theme folder inside a custom wp-content folder
register_theme_directory(WP_CONTENT_DIR . '/your-theme-folder');

Registering a theme folder inside a child theme

Explanation: The following code registers a theme folder inside a child theme. This is useful if you want to include additional themes with your child theme.

// Register a theme folder inside a child theme
register_theme_directory(get_stylesheet_directory() . '/additional-themes');

Registering a theme folder inside a mu-plugin

Explanation: If you want to include themes with a must-use plugin (mu-plugin), you can use this code to register a theme folder inside the mu-plugin.

// Register a theme folder inside a mu-plugin
register_theme_directory(WPMU_PLUGIN_DIR . '/your-mu-plugin/themes');