• 1.
    /**
  • 2.
     * Insert Image Title Into Post HTML
  • 3.
     *
  • 4.
     * Since WordPress 3.5 images inserted into posts do not have the title attribute with the image tag. 
  • 5.
     * The following functions were written by Les Bessant in his Restore Image Title plugin to restore the pre 3.5 feature.
  • 6.
     * @since	1.3
  • 7.
     * @author 	Les Bessant - https://profiles.wordpress.org/lesbessant
  • 8.
     * @refer	https://wordpress.org/plugins/restore-image-title/
  • 9.
     */
  • 10.
    function iaff_lcb_restore_image_title( $html, $id ) {
  • 11.
    	
  • 12.
    	// Get Settings
  • 13.
    	$settings = iaff_get_settings();
  • 14.
    	
  • 15.
    	// Return if disabled in settings
  • 16.
    	if ( ! ( isset( $settings['image_title_to_html'] ) && boolval( $settings['image_title_to_html'] ) ) )  {
  • 17.
    		return $html;
  • 18.
    	}
  • 19.
    	
  • 20.
    	// If html already contains a title, do nothing
  • 21.
    	if ( strpos($html, "title=") !== false ) {
  • 22.
        	return $html;
  • 23.
        }
  • 24.
    	
  • 25.
    	$attachment = get_post($id);	
  • 26.
    	$mytitle 	= esc_attr($attachment->post_title);
  • 27.
    	
  • 28.
    	return str_replace('<img', '<img title="' . $mytitle . '" '  , $html);
  • 29.
    }
  • 30.
    add_filter( 'media_send_to_editor', 'iaff_lcb_restore_image_title', 15, 2 );
  • 31.
     
  • 32.
    function iaff_lcb_restore_title_to_gallery( $content, $id ) {
  • 33.
    	
  • 34.
    	// Get Settings
  • 35.
    	$settings = iaff_get_settings();
  • 36.
    	
  • 37.
    	// Return if disabled in settings
  • 38.
    	if ( ! ( isset( $settings['image_title_to_html'] ) && boolval( $settings['image_title_to_html'] ) ) )  {
  • 39.
    		return $content;
  • 40.
    	}
  • 41.
    	
  • 42.
    	$thumb_title = get_the_title($id);
  • 43.
    	
  • 44.
    	return str_replace('<a', '<a title="' . esc_attr($thumb_title) . '" ', $content);
  • 45.
    }
  • 46.
    add_filter('wp_get_attachment_link', 'iaff_lcb_restore_title_to_gallery', 10, 4);
/** * Insert Image Title Into Post HTML * * Since WordPress 3.5 images inserted into posts do not have the title attribute with the image tag. * The following functions were written by Les Bessant in his Restore Image Title plugin to restore the pre 3.5 feature. * @since 1.3 * @author Les Bessant - https://profiles.wordpress.org/lesbessant * @refer https://wordpress.org/plugins/restore-image-title/ */ function iaff_lcb_restore_image_title( $html, $id ) { // Get Settings $settings = iaff_get_settings(); // Return if disabled in settings if ( ! ( isset( $settings['image_title_to_html'] ) && boolval( $settings['image_title_to_html'] ) ) ) { return $html; } // If html already contains a title, do nothing if ( strpos($html, "title=") !== false ) { return $html; } $attachment = get_post($id); $mytitle = esc_attr($attachment->post_title); return str_replace('<img', '<img title="' . $mytitle . '" ' , $html); } add_filter( 'media_send_to_editor', 'iaff_lcb_restore_image_title', 15, 2 ); function iaff_lcb_restore_title_to_gallery( $content, $id ) { // Get Settings $settings = iaff_get_settings(); // Return if disabled in settings if ( ! ( isset( $settings['image_title_to_html'] ) && boolval( $settings['image_title_to_html'] ) ) ) { return $content; } $thumb_title = get_the_title($id); return str_replace('<a', '<a title="' . esc_attr($thumb_title) . '" ', $content); } add_filter('wp_get_attachment_link', 'iaff_lcb_restore_title_to_gallery', 10, 4);

Copy Code to Clipboard Raw

Sign-in or Create a Free Account.

Snippi uses Twitter or Facebook to register and create accounts. Registration will enable you to keep track of your snippets. We never spam your timeline or wall. Ever.

Sign-in with Facebook Sign-in with Twitter