Welcome to Muziang Template Demonstration Station
 Western Data

Method code for automatically adding alt attribute to content image of zblog article

Channel: Model display Date: Browse: 509
 Western Data

After Zblog uploads an image and inserts it into an article, the alt attribute of the image uses the file name before the image is uploaded, and the image name often uses English or numbers. As an important tag attribute in SEO, if you use meaningless attribute values, it obviously meets the requirements of SEO, but it will take a lot of time to manually modify one by one, Therefore, it is very necessary to automatically add alt attribute values to zblog article images.

 Method code for automatically adding alt attribute to content image of zblog article

In the include.php file of the theme, add the code:

PHP
 function qiteen_setImgAlt(&$template){     global $zbp;     $article = $template->GetTags('article');     $pattern = "/<img(.*?)src=('|\")([^>]*). (bmp|gif|jpeg|jpg|png|swf)('|\")(.*?)>/i";     $replacement = '<img alt="'.$article->Title.'" src=$2$3.$4$5/>';     $content = preg_replace($pattern, $replacement, $article->Content);     $article->Content = $content;     $template->SetTags('article', $article);}

Add code to the ActivePlugin_ function in the include.php file:

PHP
 Add_Filter_Plugin('Filter_Plugin_ViewPost_Template','qiteen_setImgAlt');

After saving the file, update the cache.

 Western Data

zero Leaving a message.

comment

◎ Welcome to participate in the discussion. Please express your views and exchange your views here.
 Verification Code
 Western Data