How To: Add A Link to the WordPress Multisite Network Admin Sites List

The other day I was working on a plugin for a client when I needed to add a link to the WordPress Multisite Network Admin Sites list. This is the list of sites in your WordPress Multisite network. The links I am referring to are the action links that appear when you hover over a site in the list as shown below.

WordPress Multisite Network Sites ListTo add a link, or modify any of the existing action links, we’re going to use the manage_sites_action_links action filter in WordPress. This filter will allow us to modify the action links before they are displayed on the screen. This means you can add, or remove, any links you want.

Let’s look at the code:

add_filter( 'manage_sites_action_links', 'my_plugin_network_list_action', null, 2 );

function my_plugin_network_list_action( $actions, $blog_id ) {

    $actions = array_merge( $actions, array(
	'custom_link' => '<a href="'. network_admin_url( 'sites.php' ).'">My Custom Link</a>'
    ));

    return $actions;

}

First we call the manage_sites_action_links filter hook which executes our custom function my_plugin_network_list_action(). Our function accepts two parameters: The $actions array which contains all action links and the $blog_id which stores the site ID of the site we are hovering in the list.

To add a link we are going to use the PHP function array_merge() to merge our link into the array of existing links. In this example I added a link named “My Custom Link” which links to the Network Admin sites list. The final step is to return the $actions variable. Simple as that!

For more awesome WordPress plugin goodies check out my new book: Professional WordPress Plugin Development