lundi 23 mars 2015

How to set default value for 'Alt text' on image upload dialog?


I'm using WP 4.1.1 and trying to create a default value for the 'Alt text' when uploading an image (dropping it straight into post and dialog appears).


I've tried doing this with this hook http://ift.tt/1N3vRaD


and while I seem to be able to ADD a new field (it appears on the dialog form), I cannot modify the value of the 'Alt Text' field. So the following does NOT work (but should, according to the docs!). I have tried changing the priority from high to very low too, no difference.



add_filter('attachment_fields_to_edit', 'dpcontent_attachment_fields_to_edit', 999, 2 );

function dpcontent_attachment_fields_to_edit($form_fields, $post) {

if ( substr( $post->post_mime_type, 0, 5 ) == 'image' ) {
_log("DBG: 1 in here ... form_fields=" . arr_to_string($form_fields)); // its empty :-(

$form_fields['image_alt'] = array(
'value' => 'Hello world!',
'label' => __('Alternative Text'),
'show_in_model' => true
);
}

return $form_fields;
}


Any help with this would be greatly appreciated!


gvanto





Aucun commentaire:

Enregistrer un commentaire