کد اخری رو کمی با عجله نوشتم الان که با دقت به کد نگاه کردم دیدم میشه فشرده تر و سبک تر هم کردش. نسخه بهینه ترش میشه این.
function mehran_add_img_alt_title_process($matches) {
$title = get_the_title();
$alttext_rep = "%title";
$titletext_rep = "%title";
$override= "on";
$override_title= "on";
# take care of unsusal endings
$matches[0]=preg_replace('|([\'"])[/ ]*$|', '\1 /', $matches[0]);
### Normalize spacing around attributes.
$matches[0] = preg_replace('/\s*=\s*/', '=', substr($matches[0],0,strlen($matches[0])-2));
### Get source.
preg_match('/src\s*=\s*([\'"])?((?(1).+?|[^