- 现在百度越来越注重图片的优化效果,网站优化不可避免的需要给图片添加 ALT 属性,
- 在搜索排名中如何使用 alt 属性进行 SEO 优化:因为在 alt 属性中可以写文字,当因为图片的路径有错误而导致网页中的图片无法显示出来的时候,alt 中的文字就会显示出来,正是因为如此,我们可以在 alt 属性中写一些和文章主题或者网站主题相关的文字,这样就可以增加搜索引擎抓取的机率,有利于我们网站的排名。
实际效果对比图

教程开始
只需要在主题目录下
/** 图自动加 alt 和 title 标签属性 */
function image_alt_tag($content){
global $post;preg_match_all('/<img (.*?)\/>/', $content, $images);
if(!is_null($images)) {foreach($images[1] as $index => $value)
{$new_img = str_replace('<img', '<img alt="'.get_the_title().'-'.get_bloginfo('name').'" title="'.get_the_title().'-'.get_bloginfo('name').'"', $images[0][$index]);
$content = str_replace($images[0][$index], $new_img, $content);}}
return $content;
}
add_filter('the_content', 'image_alt_tag', 99999);
/** 自动给图片添加 alt 和 title 标签 www.llsns.com */
效果演示

© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容