Skip to main content
Improved the title and added tags
Link
birgire
  • 67.8k
  • 7
  • 119
  • 251

Add custom options to linksthe wplink dialog

Tweeted twitter.com/StackWordPress/status/738284571129712640
edited title
Link
caramba
  • 1.4k
  • 2
  • 15
  • 23

Add filter to add custom link options to links

Source Link
caramba
  • 1.4k
  • 2
  • 15
  • 23

Add filter to add custom link options

I managed to add a custom option-select for images with

function attachment_field_credit( $form_fields, $post ) {
    $field_value = get_post_meta( $post->ID, 'first_image', true );
    $isSelected1 = $field_value == '1' ? 'selected ' : '';
    $isSelected2 = $field_value != '1' ? 'selected ' : '';
    $form_fields['first_image'] = array(
        'label' => __( 'Use as first image' ),
        'input' => 'html',
        'html' => "<select name='attachments[{$post->ID}][first_image]' id='attachments[{$post->ID}][first_image]'>
                    <option ".$isSelected1." value='1'>Yes</option>
                    <option ".$isSelected2."  value='2'>No</option>
                   </select>"
    );
    return $form_fields;
}
add_filter( 'attachment_fields_to_edit', 'attachment_field_credit', 10, 2 );

Now I need to do almost the same for links. So if I click on Pages -> Add New -> Insert / Edit Link I get this:

enter image description here

Can I add another option-select field for those links? How to do that?