Skip to content

Instantly share code, notes, and snippets.

@billerickson billerickson/functions.php
Last active Dec 20, 2015

Embed
What would you like to do?
<?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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.