從SEO的策略角度看,需要將圖片上加上ALT和TITLE,來(lái)提高搜素引擎的體驗(yàn)度。一般的WORDPRESS是沒(méi)有這個(gè)功能,需要我們額外添加,這里直接用代碼實(shí)現(xiàn)。
function imagesalt($content) { global $post; $pattern ="/<img(.*?)src=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i"; $replacement = '<img$1src=$2$3.$4$5 alt="'.$post->post_title.'" title="'.$post->post_title.'"$6>'; $content = preg_replace($pattern, $replacement, $content); return $content; } add_filter('the_content', 'imagesalt'); function aimagesalt($content) { global $post; $pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i"; $replacement = '<a$1href=$2$3.$4$5 alt="'.$post->post_title.'" title="'.$post->post_title.'"$6>'; $content = preg_replace($pattern, $replacement, $content); return $content; } add_filter('the_content', 'aimagesalt');
貼到 Functions.php 中實(shí)現(xiàn)。
評(píng)論