Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Includes alt text on a Tasty Pins hidden image if none yet exists.
<?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
You can’t perform that action at this time.