Using WordPress ‘manage_link_custom_column’ PHP action

The manage_link_custom_column WordPress PHP action fires for each registered custom link column, allowing you to modify the content in the custom column.

Usage

add_action('manage_link_custom_column', 'your_custom_function', 10, 2);

function your_custom_function($column_name, $link_id) {
  // your custom code here

  return $column_name;
}

Parameters

  • $column_name (string) – Name of the custom column.
  • $link_id (int) – Link ID.

More information

See WordPress Developer Resources: manage_link_custom_column

Examples

Display the link URL in a custom column named “Link URL”.

add_action('manage_link_custom_column', 'display_link_url', 10, 2);

function display_link_url($column_name, $link_id) {
  if ($column_name == 'link_url') {
    $link = get_bookmark($link_id);
    echo $link->link_url;
  }
}

Display the link description in a custom column named “Description”.

add_action('manage_link_custom_column', 'display_link_description', 10, 2);

function display_link_description($column_name, $link_id) {
  if ($column_name == 'description') {
    $link = get_bookmark($link_id);
    echo $link->link_description;
  }
}

Show the link target in a custom column named “Link Target”.

add_action('manage_link_custom_column', 'display_link_target', 10, 2);

function display_link_target($column_name, $link_id) {
  if ($column_name == 'link_target') {
    $link = get_bookmark($link_id);
    echo $link->link_target;
  }
}

Display the link category in a custom column named “Category”.

add_action('manage_link_custom_column', 'display_link_category', 10, 2);

function display_link_category($column_name, $link_id) {
  if ($column_name == 'category') {
    $categories = get_the_link_cats($link_id);
    echo implode(', ', $categories);
  }
}

Display custom data in custom column

Show custom data associated with the link in a custom column named “Custom Data”.

add_action('manage_link_custom_column', 'display_custom_data', 10, 2);

function display_custom_data($column_name, $link_id) {
  if ($column_name == 'custom_data') {
    $custom_data = get_post_meta($link_id, 'custom_data', true);
    echo $custom_data;
  }
}

Tagged in

Leave a Comment

Your email address will not be published. Required fields are marked *