php - How to add different "title" tags to images within the loop? -


i'm trying add post title title tag image ( custom field). tried using each() function no success, maybe solution come php ? 1 of things tried:

$('.front img').each(function(){ var frontvalue = '<?php the_title_attribute(); ?>'; $(this).attr('title',frontvalue); }); 

thanks in advance !

inside loop can do:

<img src="image.jpg" alt="<?php echo get_the_title();?>"> 

or custom field:

<img src="<?php echo get_post_meta(get_the_id(), "yourcustomfieldname", true);?>" alt="<?php the_title();?>"> 

in specific case, remove last closing bracket , append alt property:

<?php $from = substr(trim($from),0,-1);        //cut last char $from .= ' alt="'.get_the_title().'">';  //append title ?> 

or better, extract url if it's old type custom field, don't touch new type custom fields (which url)

if(substr(trim($from),0,5) == '<img '){  //is img tag see?   $boom = explode('"', $from, 3);        //it is, aim quotes   $from = $boom[1];                      //salvage url } 

and rebuild img tag there. might wanna read on explode() if old format different from:

<img src="xxxxxx"> 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -