【活动】:会员128元永久会员早开早划算!
著作权归作者所有。
商业转载请联系作者获得授权,非商业转载请注明出处。
作者:极速
链接:https://www.jswu.net/2442.html
来源:https://www.jswu.net
现在百度越来越注重图片的优化效果,那么网站优化不可避免的需要给图片添加ALT属性? 根据百度百科,ALT属性用于HTML,输入纯笔墨参数属性。 次要影响是对于其他图片的无助识别,一个补救的优化步骤。 ALT 属性通过添加 ALT 标签来表示。 ALT属性是唯一能识别图片信息就显得极其紧张了。 每当我们浏览一张图片时,将鼠标移到图片上,呈现的笔墨就是ALT属性,不仅可以识别搜索引擎,还可以给用户很好的体验。 教程 请将下面的代码复制粘贴到/inc/functions.php文件里面 第一种: /** 自动给图片添加Alt标签www.jswu.net */ function image_alttitle( $imgalttitle ){ global $post; $category = get_the_category(); $flname=$category[0]->cat_name; $btitle = get_bloginfo(); $imgtitle = $post->post_title; $imgUrl = “]*src=(\”??)([^\” >]*?)\\1[^>]*>”; if(preg_match_all(“/$imgUrl/siU”,$imgalttitle,$matches,PREG_SET_ORDER)){ if( !empty($matches) ){ for ($i=0; $i < count($matches); $i++){ $tag = $url = $matches[$i][0]; $j=$i+1; $judge = ‘/title=/’; preg_match($judge,$tag,$match,PREG_OFFSET_CAPTURE); if( count($match) < 1 ) $altURL = ‘ alt=”‘.$imgtitle.’ ‘.$flname.’ 第’.$j.’张” title=”‘.$imgtitle.’ ‘.$flname.’ 第’.$j.’张-‘.$btitle.'” ‘; $url = rtrim($url,’>’); $url .= $altURL.’>’; $imgalttitle = str_replace($tag,$url,$imgalttitle); } } } return $imgalttitle; } add_filter( ‘the_content’,’image_alttitle’); /** 自动给图片添加Alt标签www.jswu.net */ 第二种: /** 自动给图片添加Alt标签 */ function image_alt_tag($content){ global $post;preg_match_all(‘//’, $content, $images); if(!is_null($images)) {foreach($images[1] as $index => $value) { $new_img = str_replace(‘/’, $content, $images); if(!is_null($images)) {foreach($images[1] as $index => $value) {$new_img = str_replace(‘
感谢您的来访,获取更多精彩文章请收藏本站。

暂无评论内容