最合适的回答,由SO网友:D. Wroblewski 整理而成
我找到了另一种方法。我在函数中添加了以下内容。php:
function yoursite_get_relative_attachment_path($path)
{
$paths = (object)parse_url($path);
return $paths->path;
}
function yoursite_wp_handle_upload($info)
{
$info[\'url\'] = yoursite_get_relative_attachment_path($info[\'url\']);
return $info;
}
add_filter(\'wp_handle_upload\', \'yoursite_wp_handle_upload\');
function yoursite_wp_get_attachment_url($url)
{
return yoursite_get_relative_attachment_path($url);
}
add_filter(\'wp_get_attachment_url\', \'yoursite_wp_get_attachment_url\');
这样wordpress将相对URL存储在db中。
有关更多详细说明,请参阅the blog where I learned about this.