Siteurl and home settings durring WordPress developemnt

When I develop sites I start on my local machine, and edit my /etc/hosts file to point to my local system. E.g. website.dev is the dev domain I might use to work on website.com locally. (This would be opposed to pointing all sites to localhost/folder/someotherfolder/website_dev or something. I just find it eaiser.)

It works great, but for WordPress sites the SiteURL and Home settings are in the database, so they need to be updated EVERY time you change domains (e.g. when I push code and database changes I was writing under website.dev to stage.website.com or something.)

A quick few lines you could add to your theme (or probably in a plugin too) to update the siteurl and home settings would be as follows.


// at top of functions php
update_option('siteurl', 'http://' . $_SERVER['HTTP_HOST']);
update_option('home', 'http://' . $_SERVER['HTTP_HOST']);

Placing that at the very top of your themes functions.php file would allow you deploy your site under a couple domains without going through the process of logging in or anything.

This entry was posted in Web Development. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="">