Using WordPress ‘link_submit_meta_box()’ PHP function

The link_submit_meta_box() WordPress PHP function displays the link create form fields.

Usage

link_submit_meta_box($link);

Parameters

  • $link (object) – Required. The current link object.

More information

See WordPress Developer Resources: link_submit_meta_box

Examples

This example displays the link create form fields using the link_submit_meta_box() function.

// Get the current link object
$link = (object) array(
    'link_name' => 'Example Link',
    'link_url' => 'https://www.example.com'
);

// Display the link create form fields
link_submit_meta_box($link);

This example adds a custom link submission form field to the link create form using the link_submit_meta_box() function.

add_action('submitlink_box', 'add_custom_link_field');

function add_custom_link_field() {
    echo '<div class="form-field">';
    echo '<label for="link_custom_field">Custom Field</label>';
    echo '<input type="text" id="link_custom_field" name="link_custom_field" />';
    echo '</div>';
}

// Display the link create form fields
link_submit_meta_box($link);

This example saves the custom link submission form field created in Example 2 using the link_submit_meta_box() function.

add_action('edit_link', 'save_custom_link_field');

function save_custom_link_field($link_id) {
    if (isset($_POST['link_custom_field'])) {
        update_link_meta($link_id, 'link_custom_field', $_POST['link_custom_field']);
    }
}

// Display the link create form fields
link_submit_meta_box($link);

This example displays the custom link submission form field value created in Example 2 using the link_submit_meta_box() function.

function display_custom_link_field_value($link) {
    $custom_field_value = get_link_meta($link->link_id, 'link_custom_field', true);
    echo 'Custom Field Value: ' . $custom_field_value;
}

add_action('link_row_actions', 'display_custom_link_field_value', 10, 1);

// Display the link create form fields
link_submit_meta_box($link);

This example deletes the custom link submission form field created in Example 2 using the link_submit_meta_box() function.

add_action('delete_link', 'delete_custom_link_field');

function delete_custom_link_field($link_id) {
    delete_link_meta($link_id, 'link_custom_field');
}

// Display the link create form fields
link_submit_meta_box($link);