Created
March 1, 2019 15:43
-
-
Save danielbachhuber/d8f99f4b612ccd74077a79b33dfa71a8 to your computer and use it in GitHub Desktop.
Includes alt text on a Tasty Pins hidden image if none yet exists.
This file contains hidden or 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 | |
/** | |
* Includes alt text on a Tasty Pins hidden image if none yet exists. | |
* | |
* @param string $image_content Image content HTML string. | |
* @param integer $hidden_image Hidden image ID. | |
* @return string | |
*/ | |
add_filter( | |
'tasty_pins_hidden_image_html', | |
function( $image_content, $hidden_image ) { | |
$alt_text = get_post_meta( $hidden_image, '_wp_attachment_image_alt', true ); | |
if ( ! $alt_text || false !== stripos( $image_content, 'alt="' ) ) { | |
return $image_content; | |
} | |
return str_replace( '<img ', '<img alt="' . esc_attr( $alt_text ) . '" ', $image_content ); | |
}, | |
10, | |
2 | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment