LoginSignup
1
2

More than 5 years have passed since last update.

URLを絶対パスから相対パスにする方法

Last updated at Posted at 2012-12-26

めも。

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'), 9999);
  }

  function replace_relative_URI($content)
  {
    $home = trailingslashit(get_home_url('/'));
    return str_replace($home, '/', $content);
  }

  function get_header()
  {
    ob_start(array(&$this, 'replace_relative_URI'));
  }

  function wp_footer()
  {
    ob_end_flush();
  }
}
new relative_URI();
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2