Last active
December 20, 2015 10:39
-
-
Save billerickson/6117268 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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