Using WordPress ‘bloginfo_url’ PHP filter

The bloginfo_url WordPress PHP filter allows you to modify the URL returned by the get_bloginfo() function.

Usage

add_filter('bloginfo_url', 'your_custom_function', 10, 2);

function your_custom_function($output, $show) {
    // your custom code here
    return $output;
}

Parameters

  • $output (string): The URL returned by get_bloginfo().
  • $show (string): The type of information requested.

More information

See WordPress Developer Resources: bloginfo_url

Examples

Change the Home URL

Modify the home URL to include a custom path.

add_filter('bloginfo_url', 'change_home_url', 10, 2);

function change_home_url($output, $show) {
    if ($show == 'url') {
        $output .= '/custom-path';
    }
    return $output;
}

Add UTM Parameters

Add UTM parameters to URLs for tracking purposes.

add_filter('bloginfo_url', 'add_utm_parameters', 10, 2);

function add_utm_parameters($output, $show) {
    if ($show == 'url') {
        $output .= '?utm_source=my_source&utm_medium=my_medium&utm_campaign=my_campaign';
    }
    return $output;
}

Change the Login URL

Modify the login URL to a custom login page.

add_filter('bloginfo_url', 'change_login_url', 10, 2);

function change_login_url($output, $show) {
    if ($show == 'wpurl') {
        $output .= '/custom-login';
    }
    return $output;
}

Add a Subdomain

Add a subdomain to the URL.

add_filter('bloginfo_url', 'add_subdomain', 10, 2);

function add_subdomain($output, $show) {
    if ($show == 'url') {
        $output = str_replace('://', '://subdomain.', $output);
    }
    return $output;
}

Change the URL Protocol

Modify the URL protocol from HTTP to HTTPS.

add_filter('bloginfo_url', 'change_url_protocol', 10, 2);

function change_url_protocol($output, $show) {
    if ($show == 'url') {
        $output = str_replace('http://', 'https://', $output);
    }
    return $output;
}