Skip to content

Instantly share code, notes, and snippets.

@billerickson
Last active December 20, 2015 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/6117268 to your computer and use it in GitHub Desktop.
Save billerickson/6117268 to your computer and use it in GitHub Desktop.
<?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