Skip to content

Instantly share code, notes, and snippets.

@shemul49rmc
Created December 13, 2013 09:46
Show Gist options
  • Save shemul49rmc/7942088 to your computer and use it in GitHub Desktop.
Save shemul49rmc/7942088 to your computer and use it in GitHub Desktop.
Add Missing Alt Tags To WordPress Images
/**
* Add Missing Alt Tags To WordPress Images By http://goo.gl/ht6fZo
*/
function add_alt_tags($content)
{
global $post;
preg_match_all('//', $content, $images);
if(!is_null($images))
{
foreach($images[1] as $index => $value)
{
if(!preg_match('/alt=/', $value))
{
$new_img = str_replace('<img', '"'.$post-post_title.'"', $images[0][$index]);
$content = str_replace($images[0][$index], $new_img, $content);
}
}
}
return $content;
}
add_filter('the_content', 'add_alt_tags', 99999);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment