Guest User

Untitled

a guest
Nov 3rd, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. function add_alt_tags($content)
  2. {
  3. global $post;
  4. preg_match_all('/<img (.*?)\/>/', $content, $images);
  5. if(!is_null($images))
  6. {
  7. foreach($images[1] as $index => $value)
  8. {
  9. if(!preg_match('/alt=/', $value))
  10. {
  11. $new_img = str_replace('<img', '<img alt="'.$post->post_title.'"', $images[0][$index]);
  12. $content = str_replace($images[0][$index], $new_img, $content);
  13. }
  14. }
  15. }
  16. return $content;
  17. }
  18. add_filter('the_content', 'add_alt_tags', 99999);
Advertisement
Add Comment
Please, Sign In to add comment