wordpress では、データベースに siteurl という項目があります。これを wp-config.php で 一時的に変更することができます。
WP_SITEURL, WP_HOME を wp-config.php で定義すれば OK です。(wordpress 3.3.1 の場合初期インストール後は、 WP_SITEURL, WP_HOME が無いので、追加してください。)
たとえばローカルでテスト環境を作ってみる、という場合は、下のようになります。
define('WP_HOME', 'http://127.0.0.1');
define('WP_SITEURL', 'http://127.0.0.1');
先頭に http:// を含め、末尾にはスラッシュを含まない形で記述します。
wp-includes/functions.php ではつぎのようになっています(wordpress 3.3.1 の場合)。
/**
* Retrieve the WordPress site URL.
*
* If the constant named 'WP_SITEURL' is defined, then the value in that
* constant will always be returned. This can be used for debugging a site on
* your localhost while not having to change the database to your URL.
*
* @access private
* @package WordPress
* @since 2.2.0
*
* @param string $url URL to set the WordPress site location.
* @return string The WordPress Site URL
*/
function _config_wp_siteurl( $url = '' ) {
if ( defined( 'WP_SITEURL' ) )
return untrailingslashit( WP_SITEURL );
return $url;
}
定数
WP_SITEURLが定義されていれば、この値を返す。データベースの URL を変更しなくても、ローカル環境でデバッグすることができる
ということで、テスト環境構築時に wordpress の URL を変更するお手軽な方法と言えるでしょう。データベースをいじらなくても良いのは楽ですね。
プログラムコメントで記述されているように、あくまでデバッグ用、ということらしいです。もし、サーバー移転でURL変更する、といった場合はデータベースの設定も変えておいたほうが良いでしょう。
[…] https://ounziw.com/2012/02/26/wp-config-php-wordpress-url/ This entry was posted in 未分類. Bookmark the […]