Exciting News! Flipper Code is now WePlugins! Same commitment to WordPress Development excellence, brand new identity.

How to use network_edit_site_nav_links filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
February 28, 2023
5 minutes read

network_edit_site_nav_links filter

Default links: ‘site-info’, ‘site-users’, ‘site-themes’, and ‘site-settings’.

To use the network_edit_site_nav_links filter, first, you have to register it using add_filter. You can write this code into the functions.php of your activated theme or in a custom WordPress Plugin.

At WePlugins, we always prefer to create a custom WordPress Plugin while using hooks so nothing breaks when you update your WordPress Theme in the future.

In the below live example, we have defined a function modify_network_edit_site_nav_links_defaults which takes 1 parameter and we registered it using add_filter. The first parameter network_edit_site_nav_links is the name of the hook. The second parameter modify_network_edit_site_nav_links_defaults is the name of the function which needs to be called. The third parameter is the priority of calling the hook if the same hook is used multiple times, and the last parameter is the number of arguments (if any) to be passed in the registered function.

Sometimes, you have to remove a registered hook, so you can use remove_filter to remove the network_edit_site_nav_links filter.

Parameters

    Below the 1 parameter is required to use this hook.

  • $links: (array) An array of link data representing individual network admin pages.
    • link_slug: (array) An array of information about the individual link to a page.
    • $label: Label to use for the link.
    • $url: URL, relative to network_admin_url() to use for the link.
    • $cap: Capability required to see the link.

Live Example

Below is an example of how you can use this hook.

  function weplugins_modify_network_edit_site_nav_links_defaults($links) { 
      // Update the $links variable according to your website requirements and return this variable. You can modify the $links variable conditionally too if you want.
      return $links; 
  }
  // add the filter
  add_filter("network_edit_site_nav_links", "weplugins_modify_network_edit_site_nav_links_defaults", 10, 1);
  

Example 1: Adding a Custom Link

In this example, we add a custom link to the network site navigation.

  function weplugins_add_custom_nav_link($links) {
      $links['custom-link'] = array(
          'label' => 'Custom Link',
          'url'   => 'admin.php?page=custom-link',
          'cap'   => 'manage_network'
      );
      return $links;
  }
  add_filter("network_edit_site_nav_links", "weplugins_add_custom_nav_link", 10, 1);
  

Example 2: Removing a Default Link

This example demonstrates how to remove the ‘site-themes’ link from the network site navigation.

  function weplugins_remove_site_themes_link($links) {
      if(isset($links['site-themes'])) {
          unset($links['site-themes']);
      }
      return $links;
  }
  add_filter("network_edit_site_nav_links", "weplugins_remove_site_themes_link", 10, 1);
  

Example 3: Modifying Link Labels

In this example, we modify the labels of the default links in the network site navigation.

  function weplugins_modify_link_labels($links) {
      foreach($links as &$link) {
          $link['label'] = 'Modified ' . $link['label'];
      }
      return $links;
  }
  add_filter("network_edit_site_nav_links", "weplugins_modify_link_labels", 10, 1);
  

Removing the Hook

To remove a hook callback, use the example below.

  remove_filter("network_edit_site_nav_links", "weplugins_modify_network_edit_site_nav_links_defaults", 10, 1);
  

Please make sure to provide the same callback function name, priority, and number of arguments while removing the hook callback.

Access Premium WordPress Plugins

Contact Us

If you need customization or have trouble using this hook, please contact our WordPress Development Team and we’d be happy to assist you.

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.