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

posts - How can I replace the text at the top of a custom column into a icon?

programmeradmin2浏览0评论

Question
How can I change the text at the top of the column into an icon ?
Example a star or a thumbs up.
Like the "Comment" field. There is no text, just a icon.

The files for the plugin is here, if you would take a look.

Question
How can I change the text at the top of the column into an icon ?
Example a star or a thumbs up.
Like the "Comment" field. There is no text, just a icon.

The files for the plugin is here, if you would take a look.
https://github.com/bjovaar/terplugin

Share Improve this question asked Mar 6, 2022 at 17:59 bjovaarbjovaar 213 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

The posts list table headings can be modified with the manage_posts_custom_column filter. Looking at how the default comment icon is handleded on WP_Posts_List_Table we can see, that you can use a html string as the column heading.

The linked plugin uses verified as the key for the custom column it adds to the table. As the plugin doesn't define an explicit priority for the anonymous functions it hooks to the filter, the callback is fired at the default priority of 10.

With this information a custom filter, with a later priority, can be added to the site to change the column title from text to icon. The filter can be either added to the theme's functions.php file or to a custom plugin. Or if you are the author of the linked plugin, then copy the sprintf part of the example to the plugin.

Example,

add_filter( 'manage_post_posts_columns', 'filter_manage_post_posts_columns', 11, 1 );
function filter_manage_post_posts_columns( $columns ) {

  // just to be sure the custom column is present
  if ( ! isset( $columns['verified'] ) ) {
    return $columns;
  }

  // Lets imitate how the default comments icon is handeled
  $columns['verified'] = sprintf(
    '<span class="dashicons dashicons-star-filled" title="%1$s"><span class="screen-reader-text">%2$s</span></span>',
    __('Recommendations', 'terplugin-lang'), // copied from the plugin to use translated text, if it exists
    __('Recommendations', 'terplugin-lang')
  );

  // modified array
  return $columns;
}

Other dashicons can be found on the Dashicon developer documentation page.

发布评论

评论列表(0)

  1. 暂无评论