|
|
多媒体库里的附件太多,一个个来设置非常麻烦,我在网上找到一段代码,说是添加到 functions.php 中即可,但是我添加了却没有任何效果,应该添加在哪个位置呢? 谢谢了.
/** Auto-Generate ALT tag for images */
function image_alt_tag($content)
{global $post;preg_match_all('/<img (.*?)\/>/', $content, $images);
if(!is_null($images)) {foreach($images[1] as $index => $value)
{if(!preg_match('/alt=/', $value)){
$new_img = str_replace('<img', '<img alt="'.get_the_title().'"', $images[0][$index]);
$content = str_replace($images[0][$index], $new_img, $content);}}}
return $content;
}
add_filter('the_content', 'image_alt_tag', 99999); |
|