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

Exhibition of works zero two hundred and seventy

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);}

ActivePlugin in the include.php file_ Add code to the function:

PHP
 Add_ Filter_ Plugin('Filter_Plugin_ViewPost_Template','qiteen_setImgAlt');

After saving the file, update the cache.

Related recommendations:

Message from netizens:

I would like to comment:

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