Support » Fixing WordPress » production vs deployment – WP_LOCATION hack – help!

  • Hi, I have searched on this topic but have not found a satisfactory answer. Here’s the deal:

    Current process:

    1. I dev a site and enter content into the local db. I have the siteurl and home set to
    2. I then use mysqldump to get an sql file.
    3. I then search and replace that sql file to change all strings from to
    4. I then import that sql file into my online database.

    This is okay, but I’d prefer to avoid the search/replace step. I found a hack whereby you add a function WP_LOCATION() to the end of wp_config.php that overrides the siteurl and home fields. It looks like this:

    define('WP_CONTENT_URL', $wpLocation."/wp-content
    function WP_LOCATION () {
        $script_path = realpath(dirname($_SERVER['SCRIPT_FILENAME']));
        $wp_base_path = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..');
        $web_subfolder = substr( $script_path, strlen($wp_base_path));
        $wp_path = $web_subfolder ? substr( dirname($_SERVER['SCRIPT_NAME']), 0, -strlen($web_subfolder) ) : dirname($_SERVER['SCRIPT_NAME']) ;
        $retval = 'http' . ($_SERVER['HTTPS'] ? 's' : null) . '://' . $_SERVER['HTTP_HOST'] . $wp_path ;
        return $retval;
    $wpLocation = WP_LOCATION();

    (found here:

    The problem:
    I found that functions like bloginfo('stylesheet_url'); and others are still returning the old url (, not and so the style.css and various images are not being loaded from the right server.

    How can I be sure that all references to the dev hostname are going to use the live hostname without having to resort to editing the sql file every time?


  • The topic ‘production vs deployment – WP_LOCATION hack – help!’ is closed to new replies.