WordPress.org

Ready to get started?Download WordPress

Forums

Restore Image Title
thanks! (1 post)

5 stars
  1. mnolf
    Member
    Posted 1 year ago #

    thanks for this handy little plugin!
    i've takent the liberty to add another few lines of code, so that it also auto-fills the alt-tag if empty:

    function lcb_restore_image_title( $html, $id ) {
    
    	$attachment = get_post($id);
        if (strpos($html, "title=")) {
        	$returnvar = $html;
        	}
        else {
    		$mytitle = esc_attr($attachment->post_title);
    		$returnvar = str_replace('<img', '<img title="' . $mytitle . '" '  , $html);
    	}
        if (strpos($returnvar, "alt=\"\"")) {
    		$mytitle = esc_attr($attachment->post_title);
    		$returnvar = str_replace("alt=\"\"", "alt=\"" . $mytitle . "\"" , $returnvar);
        }
    
    	return $returnvar;
    
    }

    feel free to include this in your plugin, if you think other people will like it.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.