Skip to content

Instantly share code, notes, and snippets.

@caralgar
Created November 18, 2015 08:28
Show Gist options
  • Save caralgar/7f8c29abb2deff5b8d79 to your computer and use it in GitHub Desktop.
Save caralgar/7f8c29abb2deff5b8d79 to your computer and use it in GitHub Desktop.
How to show title on images (general filter) - wp_get_attachment_image
<?php
add_filter( 'wp_get_attachment_image_attributes', 'add_title_to_attachment_image', 10, 2 );
function add_title_to_attachment_image( $attr, $attachment ) {
$attr['title'] = esc_attr( $attachment->post_title );
return $attr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment