絶対パスを一括で相対パスに変更する

Ads

Code

<?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();
?>
view raw gistfile1.aw hosted with ❤ by GitHub

Screen shot

Note

Description functions.phpに追記。.htaccessを使わず、サイト内のパスを一括で相対パスに変更する。環境に応じて施工する。
WordPress Ver. 3.3.1
Via WordPress で URL をすべて相対 URL にする方法