![]() |
|
||||||
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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); |
|
#2
|
||||
|
||||
|
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.
__________________
Nick "Fred and/or George Weasley" Croft Designs by Nick the Geek @Nick_theGeek on Twitter Make web design easier, get FireBug for FireFox Want to learn more about Genesis? Check out my Genesis Explained Series |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Wanted: image carousel which doesn't need GD function | Cat Dean | General Discussion | 5 | 07-12-2012 09:49 AM |
| Replacing Search Function with Image | EricaD72 | General Discussion | 2 | 11-04-2009 03:12 PM |
© Copyright 2012 Copyblogger Media LLC · StudioPress™ is a trademark of Copyblogger Media LLC
Privacy Policy | Refund Policy | Terms of Service | Affiliate Program | Contact Us