絶対パスを相対パスに書き換える

WordPressは通常絶対URLで挿入されます。

例えば

http://hpseisakuwa.com/homepage.html

と吐き出されるタグを

/homepage.html

と相対パスに書き換える方法です。

 

 

 

functions.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();

ご相談・お見積もりは無料です。まずはご連絡ください!

初めての方でも安心して進められるよう、丁寧にサポートいたします。

「まだ具体的に決まっていない」
「相談だけでも大丈夫かな?」

という方もご安心ください。

ご相談・お見積もりは無料です。
初めての方にもわかりやすくご案内いたします。

  • ホームページ制作をメールで相談
  • ホームページ制作を電話で相談
  • ホームページ制作のお見積もり依頼

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です