<?php | |
/** | |
* Image Attribute Fallback | |
* | |
*/ | |
function be_image_attr_fallback( $attr, $attachment ) { | |
if( empty( $attachment->post_parent ) ) | |
return $attr; | |
$title = get_the_title( $attachment->post_parent ); | |
if( empty( $attr['alt'] ) ) | |
$attr['alt'] = $title; | |
if( empty( $attr['title'] ) ) | |
$attr['title'] = $title; | |
return $attr; | |
} | |
add_filter( 'wp_get_attachment_image_attributes', 'be_image_attr_fallback', 10, 2 ); |
If you want an alt and title tag for every image, this uses the title of the page to which you uploaded the image as the fallback.