我有一个wordpress插件,它接受文本框中的图像,并在没有www的情况下输出它。在src。所以它看起来像这样:
<img src="http://domain.com/images/my_img.png" alt="" />
但我需要它像这样呈现客户端:
<img src="http://www.domain.com/images/my_img.png" alt="" />
显然他们声称没有www,图像不会出现,甚至以为我已经在每台计算机上测试过这个网站,我看起来很好。
我在htaccess
中添加了以下内容RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
但没有雪茄。
有谁知道如何添加www。到src =&#34; url&#34;以编程方式甚至插件?
谢谢
答案 0 :(得分:1)
也许在媒体网址上使用带有wp_get_attachment_url
挂钩的过滤器:
add_filter('wp_get_attachment_url', 'add_www_to_images_url');
function add_www_to_images_url($url) {
// if there's no www already, add it
if(false === strpos($url, '//www'))
return str_replace('//', '//www.', $url);
return $url;
}