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

How to use network_admin_url filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
June 18, 2023
5 minutes read

So, you’re diving into the world of WordPress hooks, eh? Let’s talk about the network_admin_url filter. This little gem is all about filtering the network admin URL, and it’s super handy when you’re working in a multisite environment. You know the drill—register it using add_filter in your theme’s functions.php or, even better, in a custom WordPress plugin. Trust me, keeping things in a plugin means fewer headaches when you update your theme later on.

Example 1: Basic URL Modification

Here’s a straightforward example to get you started. We define a function weplugins_modify_network_admin_url_defaults which takes three parameters. This function is then registered using add_filter.

    function weplugins_modify_network_admin_url_defaults($url, $path, $scheme) { 
        // Update the $url variable according to your website requirements and return this variable.
        return $url; 
    }
    // add the filter
    add_filter( "network_admin_url", "weplugins_modify_network_admin_url_defaults", 10, 3 );
    

Example 2: Conditional URL Modification

Want to modify the URL conditionally? No problem! Here’s how you can tweak the URL based on certain conditions.

    function weplugins_conditional_network_admin_url($url, $path, $scheme) { 
        if ($path === 'special-path') {
            $url = 'https://your-custom-domain.com/' . $path;
        }
        return $url; 
    }
    add_filter( "network_admin_url", "weplugins_conditional_network_admin_url", 10, 3 );
    

Example 3: Removing the Filter

Sometimes you need to backtrack and remove a filter. Here’s how you can remove the callback from the hook.

    remove_filter( "network_admin_url", "weplugins_modify_network_admin_url_defaults", 10, 3 );
    

Ensure you 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 any customization or run into issues, feel free to contact us for further assistance. We’re here to help!

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.