The admin_url WordPress PHP filter allows you to modify the admin area URL.
Usage
add_filter('admin_url', 'your_custom_function', 10, 4); function your_custom_function($url, $path, $blog_id, $scheme) { // your custom code here return $url; }
Parameters
$url
(string) – The complete admin area URL including scheme and path.$path
(string) – Path relative to the admin area URL. Blank string if no path is specified.$blog_id
(int|null) – Site ID, or null for the current site.$scheme
(string|null) – The scheme to use. Accepts ‘http’, ‘https’, ‘admin’, or null. Default ‘admin’, which obeys force_ssl_admin() and is_ssl().
More information
See WordPress Developer Resources: admin_url
Examples
Change admin URL to a custom subdomain
Modify the admin URL to use a custom subdomain (e.g., admin.example.com
) instead of the default example.com/wp-admin
.
add_filter('admin_url', 'custom_subdomain_admin_url', 10, 4); function custom_subdomain_admin_url($url, $path, $blog_id, $scheme) { $url = str_replace('example.com/wp-admin', 'admin.example.com', $url); return $url; }
Force HTTPS on admin URL
Ensure that the admin URL always uses the HTTPS scheme.
add_filter('admin_url', 'force_https_admin_url', 10, 4); function force_https_admin_url($url, $path, $blog_id, $scheme) { $url = set_url_scheme($url, 'https'); return $url; }
Add a custom parameter to admin URL
Add a custom query parameter (e.g., utm_source
) to the admin URL for tracking purposes.
add_filter('admin_url', 'add_custom_parameter_admin_url', 10, 4); function add_custom_parameter_admin_url($url, $path, $blog_id, $scheme) { $url = add_query_arg('utm_source', 'your_source', $url); return $url; }
Redirect to a specific admin page
Redirect all admin area requests to a specific admin page (e.g., Dashboard).
add_filter('admin_url', 'redirect_to_dashboard', 10, 4); function redirect_to_dashboard($url, $path, $blog_id, $scheme) { $url = admin_url('index.php', $scheme); return $url; }
Change admin URL for a specific site in a multisite installation
Modify the admin URL only for a specific site in a multisite installation.
add_filter('admin_url', 'change_admin_url_for_specific_site', 10, 4); function change_admin_url_for_specific_site($url, $path, $blog_id, $scheme) { if ($blog_id == 2) { // Change the admin URL only for the site with ID 2 $url = str_replace('example.com/site2/wp-admin', 'site2.example.com', $url); } return $url; }