Hello readers, today I guide you to "Add custom column to multisite sites listing screen".
In case you are running multiple sites, then you get sites listing site showing all the sites on that network. Often there might need to show some more information. Therefore let's discuss the way you can achieve this through some custom coding. You can place the custom code inside any plugin or in the active theme's functions.php file.
We will include a column to display the website id for every single of the websites. For this, we will take an assistance of wpmu_blogs_columns hook. This will take the columns list as a parameter and we'll manipulate to include another column.
Have a look at the code below.
<?php
// Hook to columns on network sites listing
add_filter( 'wpmu_blogs_columns', 'mfs_blogs_columns' );
/**
* To add a columns to the sites columns
*
* @param array
*
* @return array
*/
function mfs_blogs_columns($sites_columns)
{
$columns_1 = array_slice( $sites_columns, 0, 1 );
$columns_2 = array_slice( $sites_columns, 1 );
$sites_columns = $columns_1 + array( 'blogid' => 'Site ID' ) + $columns_2;
return $sites_columns;
}
?>
In this article, we have sliced the columns array into 2 pieces. This is because we want to place the new column at a custom position (2nd place). Whenever we simply add the column to the array, it will come at the previous.
Now we have a column for holding the site ids. The next thing we will be doing is to exhibit the site id for each sites. This time, we use another fishing hook manage_sites_custom_column. If it matches with the custom column, then we will print the significance for that column.
<?php
// Hook to manage column data on network sites listing
add_action( 'manage_sites_custom_column', 'mfs_sites_custom_column', 10, 2 );
/**
* Show blog_id
*
* @param string
* @param integer
*
* @return void
*/
function mfs_sites_custom_column($column_name, $blog_id)
{
if ( $column_name == 'blogid' ) {
echo $blog_id;
}
}
?>
We have imprinted your blog id when the column matched with the blog id steering column. That's it. You can now see a new column in the second position displaying the site/blog id.
0 Comment(s)