Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've been using the technique described in this post to remove the caption and description fields in the uploads modal window, thus eliminating unused clutter for users. Since the title field is already required when uploading images in WordPress, it's easiest for my users to dispense with the alt field altogether and just pull the alt text from the title field when displaying images on a website.

From what I'm seeing in the media.php file, I should be able to unset the alt field by adding this to my function: unset($form_fields['image_alt']);, but it's not working. Any suggestions as to what I might be doing wrong?

share|improve this question
    
This would be very bad for your site: the alt attribute is reserved for a functional equivalent of the image. It cannot be the same as the title. Just imagine you were forced to use a screen reader and had to listen to each title twice. –  toscho Nov 16 '12 at 23:40
    
Have you read the article linked at? wordpress.stackexchange.com/q/5645/5424. Using the pre 3.5 uploader this should work. –  Cor van Noorloos Nov 17 '12 at 6:31
    
@toscho My problem is that most users leave the alt field empty, which is a bigger issue for SEO and accessibility. Using this approach I can at least ensure there will be some alt text, and either disable the title field completely in the output or auto-populate it. –  Sam Nov 20 '12 at 20:16

1 Answer 1

up vote 1 down vote accepted

Considering that you will come up with a solution to the accessibility issue pointed by @toscho...

Putting a lower priority (later execution) to the filter does the job.

$priority (integer) (optional)
Used to specify the order in which the functions associated with a particular action are executed. Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
Default: 10

function remove_caption( $fields ) {
    unset( $fields['image_alt'] );
    return $fields;
}
add_filter( 'attachment_fields_to_edit', 'remove_caption', 999, 1 );
share|improve this answer
    
999 is an exaggeration... 11 is enough, 15 just to be sure :) –  brasofilo Nov 17 '12 at 10:38
    
Perfect! Didn't realize I could change the priority, though it looked like that was causing the issue. Works great now. –  Sam Nov 20 '12 at 20:12
    
Is this still relevant? I am running 3.9.1 and this code does not work for me. –  3x5 May 27 at 17:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.