• Until WP 3.6 it was possible to remove the “alt” field (and also the “caption” field) before showing a post of type “attachment” through attachment_fields_to_edit hook.

    WP removed the possibility to…remove fields from that hook from 3.6 version on.

    Do you know other methods to get this result in WP, or I have to resort to a Css-only solution?

    • This topic was modified 7 years, 9 months ago by Aminta.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    Less reliable because it’s theme dependent, but you could manage the content on output. If the theme uses wp_get_attachment_image(), you can use the ‘wp_get_attachment_image_attributes’ filter to remove the alt attribute from output.

    Similarly, if the_excerpt() is used for the caption, use the ‘the_excerpt’ filter. I believe these functions are commonly used by most themes, so should be fairly reliable.

    Thread Starter Aminta

    (@aminta)

    Thanks for your answer, I’ve tried this:

    function alt_filter($attr) {
    	
    	// var_dump($attr);
    	// array(5) { ["src"] ["class"] ["alt"] ["srcset"] ["sizes"] }
    	
    	$attr["alt"] = 'showme';
    	
    	return $attr;
    	
    };
    
    add_filter( 'wp_get_attachment_image_attributes', 'alt_filter', 10, 2 );

    But in /wp-admin/post.php?post=184&action=edit it doesn’t change nothing, why?

    • This reply was modified 7 years, 9 months ago by Aminta.
    Moderator bcworkz

    (@bcworkz)

    Yeah, my solution does not affect the back end, the attribute is stripped on output.

    Thread Starter Aminta

    (@aminta)

    Ok but what for the backend? Only a Css-JS solution?

    Moderator bcworkz

    (@bcworkz)

    Perhaps. I don’t know where the back end content actually comes from, so I couldn’t say for sure.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to hide / remove attachment “alt” or “caption” field in Admin?’ is closed to new replies.