2

Just wondering if it's possible to add a header before fields added with the attachment_fields_to_edit() filter, just like the one before the attachment display fields.

Any ideas?

Thanks

enter image description here

PHP:

function my_attachment_fields_to_edit( $form_fields, $post ) {
    $form_fields['attachment-url'] = array(
        'label' => __( 'URL', 'plugin' ),
        'input' => 'text',
        'value' => get_post_meta( $post->ID, '_attachment_url', true )
    );
    $form_fields['attachment-width'] = array(
        'label' => __( 'Width', 'plugin' ),
        'input' => 'text',
        'value' => get_post_meta( $post->ID, '_attachment_width', true )
    );
    $form_fields['attachment-height'] = array(
        'label' => __( 'Height', 'plugin' ),
        'input' => 'text',
        'value' => get_post_meta( $post->ID, '_attachment_height', true )
    );
    return $form_fields;
}
1

I've found out that you can use the tr attribute for creating entire rows:

function my_attachment_fields_to_edit( $form_fields, $post ) {
    $form_fields['attachment-header']['tr'] = '
        <tr>
            <td colspan="2">
                <h2>My title</h2>
            </td>
        </tr>';
    $form_fields['attachment-url'] = array(
        'label' => __( 'URL', 'plugin' ),
        'input' => 'text',
        'value' => get_post_meta( $post->ID, '_attachment_url', true )
    );
    $form_fields['attachment-width'] = array(
        'label' => __( 'Width', 'plugin' ),
        'input' => 'text',
        'value' => get_post_meta( $post->ID, '_attachment_width', true )
    );
    $form_fields['attachment-height'] = array(
        'label' => __( 'Height', 'plugin' ),
        'input' => 'text',
        'value' => get_post_meta( $post->ID, '_attachment_height', true )
    );
    return $form_fields;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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