Opened 5 years ago
Last modified 5 years ago
#47002 new enhancement
Create wp_theme_directory_constants() function and dynamic WordPress Themes folder
Reported by: | mehrshaddarzi | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Themes | Keywords: | has-patch needs-testing |
Focuses: | Cc: |
Description
One of the needs of WordPress users is to dynamically modify the themes folder.
For Change themes folder name in (wp-content dir) you can added this code in wp-config.php :
define( 'WP_THEMES_DIR', "template" );
also for change complete path and url :
define( 'WP_THEMES_PATH', ABSPATH . "/public/template" ); define( 'WP_THEMES_URL', WP_SITEURL . "/public/template" );
This item works for WordPress Multi-site without problems.
Attachments (3)
Change History (7)
#2
@
5 years ago
- Component changed from General to Themes
- Keywords reporter-feedback added; dev-feedback removed
#3
@
5 years ago
@SergeyBiryukov
There is a bug between register_theme_directory()
and theme_root
filter
For example, I wanted to changed the WordPress themes folder.
- i renamed
themes
folder totemplates
. - i moved
~/home/wp-content/templates
to~/home/public/templates
. - i created a mu-plugins with
themes-dir.php
and put the following code.
<?php /** * Plugin Name: Change Themes folder * Description: A WordPress Plugin For Change themes folder * Author: Mehrshad Darzi * Version: 1.0.0 */ register_theme_directory( ABSPATH . 'public/templates' ); add_filter( 'theme_root', function () { return ABSPATH . 'public/templates'; }); add_filter( 'theme_root_uri', function () { return home_url( '/public/templates' ); }, 10, 1 );
I got this error : ERROR: The theme directory "twentynineteen" does not exist.
.
then I reviewed the WordPress core code and found two wrong codes.
wp-includes/theme.php
line 661 and 373.
if ( ! is_array( $wp_theme_directories ) || count( $wp_theme_directories ) <= 1 ) {
return '/themes';
}
top code is wrong because theme_root
filter not considered.
i changed code to :
if ( ( ! is_array( $wp_theme_directories ) || count( $wp_theme_directories ) <= 1 ) and ! has_filter( 'theme_root' ) ) {
return '/themes';
}
And worked without problems.
i Created a new patch that Fixed all problem about WordPress themes according to register_theme_directory()
function.
please check.
Hi @mehrshaddarzi, welcome to WordPress Trac! Thanks for the ticket.
Have you considered using register_theme_directory() instead?