发布文章时 怎么写alt title?这个问题,一般是WordPress在发布文章时该如何自动给图片添加title及Alt属性呢?下面开始展开:【代码编写】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="'$'第'$'张" title="'$'第'$'张-'$'" '; $url = rtrim($url,'>'); $url = $altURL'>'; $imgalttitle = str_replace($tag,$url,$imgalttitle); } } } return $imgalttitle;}