Support » Plugins » Hacks » Functions.php: How to make wordpress figure out the siteurl and home by itself?

  • Resolved ketri


    Here on Codex it says:

    Each time you download a copy of your database from live down to your development server, you’ll have to remember to update your database again. Fortunately, there’s a simple hack for functions.php that can doesn’t require you to update your database. Note: with this hack activated, WordPress will IGNORE values you’ve configured for siteurl and home in your Options, and work them out for itself.

    What is this hack and how to use it?

    And did I understand correctly, that when using this I can just import and export my database to local and remote without changing those values in the database.

    Thank you very much.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Found this which has code that goes in to config.php.

    How would one use this? Can I now use a database that has any home and siteurl -values?

    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;
    Moderator bcworkz


    That hack will only work on older WP versions. You need to use the method described in this section. Note that this involves a core hack, which is generally highly discouraged. As such, it is questionable to even suggest such a thing in the Codex. Seeing that it is being applied to a development copy as a convenience to avoid constantly hacking the DB, I guess it is forgivable.

    What this means for you is every time you update WP, you will need to reapply this hack. I can see this is preferable to constantly hacking the latest DB copy as described in the mySQL code above the referenced section.

    If you understand the code, you can see the correct values replace whatever is in the DB anytime such data is requested, so what’s in the DB can be anything.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Functions.php: How to make wordpress figure out the siteurl and home by itself?’ is closed to new replies.