織夢怎么讓文章中圖片自動添加ALT屬性,dedecms
導讀:dedecmsdedecms打開/include/extend.func.php文件 在最下面加入: //文章body優化替換 function replaceurl($newurl) {夢織模板織夢網站模板。
打開/include/extend.func.php文件
在最下面加入:
//文章body優化替換
function replaceurl($newurl)
&nbsdede模板堂p; {
global $dsql,$id;
//獲取圖片附加表imgurls字段內容進行處
$row = $dsql->GetOne("SELECT title FROM dede_archives where id=$id");
//替換圖片Alt為文檔標題
$newurl=str_ireplace(array('alt=""','alt=\'\''),'',$newurl);
$newurl=preg_replace("@ [\s]{0,}alt[\s]{0,}=[\"'\s]{0,}[\s\S]{0,}[\"'\s] @isU"," ",$newurl);
$newurl=str_ireplace("<img " ,"<img alt=\"".$row['title']."\"",$newurl);
//去掉結尾空格
$newurl=str_ireplace(" /","/",$newurl);
$newurl=str_ireplace(" />",&夢織模板quot;/>",$newurl);
return $newurl;
}
前端調用代碼:
{dede:field.body function='replaceurl(@me)'/}
需要圖片中的style width height屬性就把上面代碼修改成下面的代碼
//文章body優化替換
function replaceurl($newurl)
{
global $dsql,$id;
//獲取圖片附加表imgurls字段內容進行處
$row = $dsql->GetOne("SELECT title FROM dede_archives where id=$id");
//去掉img的width和height
$newurl=preg_replace('/style=\"width\:(.*)\"/','',$newurl);
//替換圖片Alt為文檔標題
$newurl=str_ireplace(array('alt=""','alt=\'\''),'',$newurl);
$newurl=preg_replace("@ [\s]{0,}alt[\s]{0,}=[\"'\s]{0,}[\s\S]{0,}[\"'\s] @isU"," ",$newurl);
$newurl=str_ireplace("<img " ,"<dede后臺模板img alt=\"".$row['title']."\"",$newurl);
//去掉結尾空格
$newurl=str_ireplace(" /","/",$newurl);
$newurl=str_ireplace(" />","/>",$newurl);
return $newurl;
}
相關夢織模板織夢網站模板。
聲明: 本文由我的SEOUC技術文章主頁發布于:2023-07-17 ,文章織夢怎么讓文章中圖片自動添加ALT屬性,dedecms主要講述屬性,標簽,織夢網站建設源碼以及服務器配置搭建相關技術文章。轉載請保留鏈接: http://www.bifwcx.com/article/web_28738.html