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
1 Answer
Reset to default 1The 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.