Skip to content

Instantly share code, notes, and snippets.

@danielbachhuber
Created March 1, 2019 15:43
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 danielbachhuber/d8f99f4b612ccd74077a79b33dfa71a8 to your computer and use it in GitHub Desktop.
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.
<?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