StudioPress Community Forums
  StudioPress Community Forums > Forums > General Discussion
For help and support, access to your downloads, or to manage your account please log into My StudioPress.

These forums have been set to read-only so you can browse the existing topics for any questions you may have.

For general discussion on WordPress, CSS and design (NOT for support) visit the new Community Forums.
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 11-11-2012, 04:33 AM
Markoi Markoi is offline
Registered User
Pro Plus Member
 
Join Date: Nov 2008
Posts: 61
Default 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);
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT -5. The time now is 07:31 AM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.