I want to add an additional column in the multisite Sites page (sites.php). Found this code on this SO:
add_filter('wpmu_blogs_columns', 'xx_add_expired_date_column');
function xx_add_expired_date_column($site_columns) {
$site_columns['expired_Date'] = 'Expires';
return $site_columns;
}
/* Populate site_name with blogs site_name */
add_action('manage_sites_custom_column', 'xx_exipred_date_data', 10, 2);
function xx_exipred_date_data($column_name, $blog_id) {
$current_blog_details = get_blog_details(array('blog_id' => $blog_id));
echo ucwords($current_blog_details->blogname);
}
The wpmu_blogs_columns
filter should add the additional column on the Sites screen. I put this code in a plugin I am developing. Other functions of that plugin are working properly. The plugin has been network activated.
When I look at the Sites list (Network Admin, Sites, or via the Network dashboard Sites, All Sites), the extra column is not there.
If I put a die()
statement after the xx_add_expired_date_column
function, that 'die' never happens.
I think it may be a loading sequence error - maybe the plugin is not being loaded on the Sites page? What can be done to enable this additional column?
Added 7 Feb 2023
Further testing: the wpmu_blogs_columns
filter will work in the theme's (or Child Theme's) functions.php
file, but not in a plugin.
Added 8 Feb 2023
As mentioned in the soon-to-be-accepted answer, the column array is $sites_columns (plural 'sites'). And the $column_name is important. The code in the answer will work.