0

In wp-config.php I have the following code to change the website path based on the environment of the website.

if ( theme_get_environment() === 'local' ) {
    define( 'WP_HOME', 'http://website.local' );
    define( 'WP_SITEURL', 'http://website.local' );
}

The database wp_home and wp_siteurl are pointing to the live website. But that is fine because that way I don't need an else statement to also define paths for the website.nl domain.

Now the problem is that when I use get_theme_file_uri() it returns this path: http://website.nl/wp-content/themes/theme2018. That should be a .local path! So how to fix this?

I already tried to use this approach in wp-config.php, but it didn't work:

if ( theme_get_environment() === 'local' ) {
    define( 'WP_HOME', 'http://website.local' );
    define( 'WP_SITEURL', 'http://website.local' );

    // fix theme directory uri for local website
    register_theme_directory('http://' . $_SERVER['HTTP_HOST'] . '/wp- 
    content/themes/theme2018');
}

So how can I fix the result of get_theme_file_uri() to be a local path. Without changing the database values? Defining WP_HOME and WPSITEURL should be enough, right?

1 Answer 1

3

Just found out a solution: The WP_HOME and WP_SITEURL DEFINE statements need to be above the wp-settings.php include rule inside of wp-config.php.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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