Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class relative_URI { | |
function relative_URI() { | |
add_action('get_header', array(&$this, 'get_header'), 1); | |
add_action('wp_footer', array(&$this, 'wp_footer'), 99999); | |
} | |
function replace_relative_URI($content) { | |
$home_url = trailingslashit(get_home_url('/')); | |
//サブディレクトリに置いている場合は./等と変更する | |
return str_replace($home_url, '/', $content); | |
} | |
function get_header(){ | |
ob_start(array(&$this, 'replace_relative_URI')); | |
} | |
function wp_footer(){ | |
ob_end_flush(); | |
} | |
} | |
new relative_URI(); | |
?> |
Screen shot
Note
Description | functions.phpに追記。.htaccessを使わず、サイト内のパスを一括で相対パスに変更する。環境に応じて施工する。 |
---|---|
WordPress Ver. | 3.3.1 |
Via | WordPress で URL をすべて相対 URL にする方法 |