WordPressを相対パスに変更(サブディレクトリ対応)
WordPressをサブディレクトリにインストールしたときに、相対パスに変更するようにします。
[php]
<?php
//絶対パス→相対パス
class relative_URI {
public function __construct() {
add_action('get_header', array(&$this, 'get_header'), 1);
add_action('wp_footer', array(&$this, 'wp_footer'), 99999);
}
protected function replace_relative_URI($content) {
$home_url = trailingslashit(get_home_url('/'));
$top_url = preg_replace( '/^(https?:\/\/.+?)\/(.*)$/', '$1', $home_url );
return str_replace( $top_url, '', $content );
}
public function get_header(){
ob_start(array(&$this, 'replace_relative_URI'));
}
public function wp_footer(){
ob_end_flush();
}
}
$relative_URI = new relative_URI();
?>
[/php]
参考サイトはあるのですが、どこのサイトか忘れてしまったため見つけ次第リンク貼らせて頂きます。
個人支援・寄付について
サイトラボでは個人支援・寄付を受けております。ご協力いただける方はお願いいたします。当サイトではビットコインで受け付けております。
- ビットコイン:3LHnADwZwUbic2L45EnVJEykiG6KfbqrwS