最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to add a column into the link manager?

programmeradmin5浏览0评论

Inside WordPress admin panel, there is the "old" link manager, know also a Bloggroll.

It has multiple columns in the overview, and I would like to add a column. How can I do this?

(I only want to know, how to add a column into the overview. Or with other words: How can I add some HTML code to the output?)

This link manager is available with http://domain/wp-admin/link-manager.php

Inside WordPress admin panel, there is the "old" link manager, know also a Bloggroll.

It has multiple columns in the overview, and I would like to add a column. How can I do this?

(I only want to know, how to add a column into the overview. Or with other words: How can I add some HTML code to the output?)

This link manager is available with http://domain/wp-admin/link-manager.php

Share Improve this question edited Apr 16, 2020 at 7:28 Tahtu asked Apr 16, 2020 at 6:34 TahtuTahtu 1173 bronze badges 3
  • did you mean you want to add columns in admin screen when you list out the links? – 西門 正 Code Guy - JingCodeGuy Commented Apr 16, 2020 at 7:18
  • @simongcc: Yes. (I've edit the question, thank you.) – Tahtu Commented Apr 16, 2020 at 7:29
  • I have revised the solutions specified for link and explained the reason. – 西門 正 Code Guy - JingCodeGuy Commented Apr 16, 2020 at 8:43
Add a comment  | 

1 Answer 1

Reset to default 0

Normally, default post and custom post type screen could use the following

  • manage_{$screen->id}_columns - for custom column header
  • manage_posts_custom_column - for custom column data for non-hierarchical post types OR manage_{$post->post_type}_posts_custom_column - any custom post-types

However, links is not a post type and the data is in its own database table, different to post table.

While the column header still follows the above filter. For the column data of the list in link manager, the filter is manage_link_custom_column

You may use the following code to do so. The following is tested on theme functions.php and proved to work assumed there is no interference from other plugins and the theme itself.

// add column header
add_filter('manage_link-manager_columns', 'add_columns_to_lm');
function add_columns_to_lm( $columns )
    {
        $newcolumns = array(
            'custom_header' => 'new custom header', // header key => value
    );
    $columns = array_merge($newcolumns, $columns); // just one of the writing style, it is up to you to change

    return $columns;
}

// add column data
add_action('manage_link_custom_column', 'add_column_data_to_lm', 10, 2);
function add_column_data_to_lm( $column, $link_id ) {
    //  var_dump( $link_id ) // for manipulations

     if( $column === 'custom_header' ) { // match the header key which you define the new header
        echo 'something inside';
     }
}
发布评论

评论列表(0)

  1. 暂无评论