I have the following filter, but do not know how to add custom attributes to image field, when attaching media to post.
example
<img data-ext-link-title="" data-ext-link-url="">
functions.php
function pp_external_link_edit( $form_fields, $post ) {
$form_fields['pp-external-link-title'] = array(
'label' => 'External Link Title',
'input' => 'text',
'value' => get_post_meta( $post->ID, 'pp_external_link_title', true ),
'helps' => 'Link for button at bottom of pretty photo modal',
);
$form_fields['pp-external-link-url'] = array(
'label' => 'External Link URL',
'input' => 'text',
'value' => get_post_meta( $post->ID, 'pp_external_link_url', true ),
'helps' => 'Link for button at bottom of pretty photo modal',
);
return $form_fields;
}
add_filter( 'attachment_fields_to_edit', 'pp_external_link_edit', 10, 2 );
function pp_external_link_save( $post, $attachment ) {
if( isset( $attachment['pp-external-link-title'] ) )
update_post_meta( $post['ID'], 'pp_external_link_title', $attachment['pp-external-link-title']);
if( isset( $attachment['pp-external-link-url'] ) )
update_post_meta( $post['ID'], 'pp_external_link_url', $attachment['pp-external-link-url']);
return $post;
}
add_filter( 'attachment_fields_to_save', 'pp_external_link_save', 10, 2 );