Override WordPress URL

By  on  

When I migrated my website between Media Temple servers, I wanted to manually test the site to ensure no server configuration differences between the server were bricking the site.  The obvious problem I would encounter is that links would be broken because the site wasn't living on my domain name yet.  I did some research and found a way to easily override the WordPress site and home URLs:

define('WP_HOME', 'http://867.53.0.9');
define('WP_SITEURL', 'http://867.53.0.9');

Defining these values within the wp-config.php file allows me to override the database values for the home and site-wide domain settings;  now the site is easily testable before flipping the switch on domain settings!

Recent Features

  • By
    Vibration API

    Many of the new APIs provided to us by browser vendors are more targeted toward the mobile user than the desktop user.  One of those simple APIs the Vibration API.  The Vibration API allows developers to direct the device, using JavaScript, to vibrate in...

  • By
    Camera and Video Control with HTML5

    Client-side APIs on mobile and desktop devices are quickly providing the same APIs.  Of course our mobile devices got access to some of these APIs first, but those APIs are slowly making their way to the desktop.  One of those APIs is the getUserMedia API...

Incredible Demos

  • By
    Introducing MooTools Templated

    One major problem with creating UI components with the MooTools JavaScript framework is that there isn't a great way of allowing customization of template and ease of node creation. As of today, there are two ways of creating: new Element Madness The first way to create UI-driven...

  • By
    Xbox Live Gamer API

    My sharpshooter status aside, I've always been surprised upset that Microsoft has never provided an API for the vast amount of information about users, the games they play, and statistics within the games. Namely, I'd like to publicly shame every n00b I've baptized with my...

Discussion

  1. Once again David, another awesome and super useful article I’ll share with people for sure. Keep up the good work! Let us know if you ever need anything.

    Drew J
    (mt) Media Temple
    @MediaTempleHelp

  2. Jeremiah Megel

    867.53.0.9: Jenny needs to get a valid IP address.

  3. I like this technique:

    if ( file_exists( dirname( __FILE__ ) . '/local-config.php' ) ) {
    	define( 'WP_LOCAL_DEV', true );
    	include( dirname( __FILE__ ) . '/local-config.php' );
    } else {
    	define( 'WP_LOCAL_DEV', false );
    	define( 'DB_NAME', 'dbname' );
    	define( 'DB_USER', 'dbuser' );
    	define( 'DB_PASSWORD', 'passw0rd' );
    	define( 'DB_HOST', 'localhost' );
    }
    

    Now you make sure local-config.php is in your .gitignore file, and you can git push your WordPress install to your server.

  4. BlaineSch

    Wouldn’t it be easier to edit your host file?

    • Yeah, probably, but most non-tech people would try to avoid that.

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!