![]() |
Beter image SEO function
Could someone help me with some code to drop in my functions.php to have beter image SEO.
When i write a post i always set a custom image title tag for my images. But what i want is when the alt tag is empty the image title tag is taken to set the alt tag. This function isn't working: /** 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); |
Why go through all this extra work instead of just writing good alt tags. Alt tags are much more important to SEO than a title tag so that should be the best practice for adding images. Additionally, alt tags really shouldn't be the same as title tags.
|
| All times are GMT -5. The time now is 05:29 PM. |
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.