Friday 31 January 2014

How to make Wordpress root-relative

Add the following lines to your wp-config file (found in the root).


define('WP_HOME',"http://" . $_SERVER['HTTP_HOST']);
define('WP_SITEURL',"http://" . $_SERVER['HTTP_HOST']);

define( 'WP_CONTENT_DIR',  dirname( __FILE__ ) . '/wp-content' );
define( 'WP_CONTENT_URL',  'http://' . $_SERVER['HTTP_HOST'] . '/wp-content' );
//  added by chetan Custom plugin directory
define( 'WP_PLUGIN_DIR',   dirname( __FILE__ ) . '/wp-content/plugins' );
define( 'WP_PLUGIN_URL',   'http://' . $_SERVER['HTTP_HOST'] . '/wp-content/plugins' );

Then prevent the functions get_site_url() and  get_home_url from accessing the wp_options database table to get the server domain or ip.

For this edit the link-template.php file:

Find the function get_home_url and comment every occurrence of this line like so:
//        $url = get_option( 'home' );

and add this:

    $url = "http://" . $_SERVER['HTTP_HOST'];

Do the same for get_site_url():

//        $url = get_option( 'siteurl' );

and add this:

    $url = "http://" . $_SERVER['HTTP_HOST'];


Now, to make sure any media files that are uploaded use root relative urls, install the following plugin:

http://wordpress.org/plugins/root-relative-urls/


No comments:

Post a Comment