Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Can we change the title and alt attributes of the_post_thumbnails and set them to post title instead ? like creating a function for it and adding a filter ? I tried searching but I can't seem to find what I want.

and thanks in advance.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Look at this http://codex.wordpress.org/Function_Reference/the_post_thumbnail

second argument in this function you can set a few set fields, such as alt, title, source and class:

$default_attr = array(
        'src'   => $src,
        'class' => "attachment-$size",
        'alt'   => trim(strip_tags( wp_postmeta->_wp_attachment_image_alt )),
        'title' => trim(strip_tags( $attachment->post_title )),
    );
share|improve this answer

try this

$title_attribute = the_title_attribute( array( 'echo' => FALSE ) );
the_post_thumbnail(
    'full', 
    array(
        'alt'   => $title_attribute, 
        'title' => $title_attribute 
    )
);
share|improve this answer
2  
Please explain why that could solve the problem. –  toscho Mar 9 '13 at 12:56
    
i've need in some website so i've tried below code its not work sometimes or may my coding mistake or so i've tried above my code and its work fine... but may i know why you are asking about it...? –  Rameez SOOMRO Mar 9 '13 at 14:00
2  
" but may i know why you are asking about it...? "... because answers should be explanations not raw code dumps. –  s_ha_dum Mar 9 '13 at 14:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.