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

Exhibition of works zero two hundred and twenty-four

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 is often in English or numbers. As an important tag attribute in SEO, if you use meaningless attribute values, it obviously meets the requirements of SEO, but manually modifying one by one will take a lot of time, Therefore, it is necessary to automatically add alt attribute value to zblog article images.

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

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

In the activeplugin of 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:

Comments from netizens:

I would like to comment:

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