WordPress HTTPS プラグインで管理画面を https にすると、記事やページに挿入する画像のパスまで https になってしまい困ります。
以下のスクリプトを functions.php に。
functions.php
function delete_host_from_attachment_url($url) {
$regex = '/^http(s)?:\/\/[^\/\s]+(.*)$/';
if (preg_match($regex, $url, $m)) {
$url = $m[2];
}
return $url;
}
add_filter('wp_get_attachment_url', 'delete_host_from_attachment_url');
add_filter('attachment_link', 'delete_host_from_attachment_url');
サイトの移行の際にもパスを書き換えなくてすむので、便利です。