Opened 8 years ago
Closed 3 years ago
#40467 closed defect (bug) (invalid)
Hardcoding Template and Stylesheet paths inside the wp-config.php leads to "constant already defined in default-constants.php"
Reported by: | anonymized_13423376 | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Themes | Keywords: | has-patch reporter-feedback |
Focuses: | template, performance | Cc: |
Description
I've tried to hardcode the Template and Stylesheet directory inside the wp-config with:
<?php define('TEMPLATEPATH', '/app/public/wp-content/themes/twentyseventeen'); define('STYLESHEETPATH', '/app/public/wp-content/themes/twentyseventeen');
The paths I've got from
get_template_directory()
and
get_stylesheet_directory()
I've tried with WP 4.7.3 on Local from Flywheel with Twentyseventeen as theme. But as soon as I save the two defines I get:
Notice: Constant TEMPLATEPATH already defined in /app/public/wp-includes/default-constants.php on line 343 Notice: Constant STYLESHEETPATH already defined in /app/public/wp-includes/default-constants.php on line 349
I've also tried with :
<?php define( ‘TEMPLATEPATH’, get_template_directory() ); define( ‘STYLESHEETPATH’, get_stylesheet_directory() );
liked listed in the codex:
https://codex.wordpress.org/Editing_wp-config.php
But that resulted in
Fatal error: Call to undefined function get_template_directory() in /app/public/wp-config.php on line 75
But it could be easily fixed by adding if statements inside the default-constants.php function for TEMPLATEPATH and STYLESHEETPATH I suppose
Attachments (1)
Change History (4)
#3
@
3 years ago
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
Hello @rkoller,
Welcome back to WordPress Core Trac!
The notices you're seeing are because these two constants are defined in wp-includes/default-constants.php
. The fatal error is because those functions have not yet been loaded into memory.
The constants are defined and populated during the initialization of WordPress.
WordPress automatically populates those constants using the activated theme. See the docs for `get_stylesheet_directory()` and `get_template_directory()`.
Why hardcode the absolute path to the current theme rather than activating the theme and letting WordPress automatically detect and set the absolute path? Is there a compelling reason?
As it's been over 4 years with no activity and the errors are doing it wrong, closing this ticket.
@rkoller if there's a compelling reason to hardcode the constants, please reopen and share the why and reasoning for further discussion and consideration.
Note: please don't be offended by the close reason of `invalid`, as this keyword means it's not a bug.
patch