Using WordPress ‘manage_sites_custom_column’ PHP action

The manage_sites_custom_column WordPress PHP action allows you to add custom content to each registered custom column in the Sites list table.

Usage

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

function your_custom_function($column_name, $blog_id) {
    // your custom code here
    return $column_name;
}

Parameters

  • $column_name (string) – The name of the column to display.
  • $blog_id (int) – The site ID.

More information

See WordPress Developer Resources: manage_sites_custom_column

Examples

Adding a custom column with site description

Add a new custom column called “Site Description” and display the site description in that column.

add_filter('wpmu_blogs_columns', 'add_site_description_column');
add_action('manage_sites_custom_column', 'display_site_description', 10, 2);

function add_site_description_column($columns) {
    $columns['site_description'] = 'Site Description';
    return $columns;
}

function display_site_description($column_name, $blog_id) {
    if ($column_name == 'site_description') {
        $description = get_blog_option($blog_id, 'blogdescription');
        echo $description;
    }
}

Displaying site administrator email

Add a custom column called “Site Admin Email” and display the site administrator’s email address in that column.

add_filter('wpmu_blogs_columns', 'add_site_admin_email_column');
add_action('manage_sites_custom_column', 'display_site_admin_email', 10, 2);

function add_site_admin_email_column($columns) {
    $columns['site_admin_email'] = 'Site Admin Email';
    return $columns;
}

function display_site_admin_email($column_name, $blog_id) {
    if ($column_name == 'site_admin_email') {
        $admin_email = get_blog_option($blog_id, 'admin_email');
        echo $admin_email;
    }
}

Show the site’s language

Add a custom column called “Site Language” and display the site’s language in that column.

add_filter('wpmu_blogs_columns', 'add_site_language_column');
add_action('manage_sites_custom_column', 'display_site_language', 10, 2);

function add_site_language_column($columns) {
    $columns['site_language'] = 'Site Language';
    return $columns;
}

function display_site_language($column_name, $blog_id) {
    if ($column_name == 'site_language') {
        $language = get_blog_option($blog_id, 'WPLANG');
        echo $language;
    }
}

Display site creation date

Add a custom column called “Site Creation Date” and display the site creation date in that column.

add_filter('wpmu_blogs_columns', 'add_site_creation_date_column');
add_action('manage_sites_custom_column', 'display_site_creation_date', 10, 2);

function add_site_creation_date_column($columns) {
    $columns['site_creation_date'] = 'Site Creation Date';
    return $columns;
}

function display_site_creation_date($column_name, $blog_id) {
    if ($column_name == 'site_creation_date') {
        $site_details = get_blog_details($blog_id);
        echo $site_details->registered;
    }
}

Display the number of users for each site

Add a custom column called “Number of Users” and display the number of users for each site in that column.

add_filter('wpmu_blogs_columns', 'add_number_of_users_column');
add_action('manage_sites_custom_column', 'display_number_of_users', 10, 2);

function add_number_of_users_column($columns) {
    $columns['number_of_users'] = 'Number of Users';
    return $columns;
}

function display_number_of_users($column_name, $blog_id) {
    if ($column_name == 'number_of_users') {
        $users_count = count_users($blog_id);
        echo $users_count['total_users'];
    }
}