The get_custom_logo WordPress PHP filter allows you to modify the custom logo output on your WordPress website.
Usage
add_filter('get_custom_logo', 'your_custom_function_name', 10, 2);
function your_custom_function_name($html, $blog_id) {
// your custom code here
return $html;
}
Parameters
- $html (string): Custom logo HTML output.
- $blog_id (int): ID of the blog to get the custom logo for.
More information
See WordPress Developer Resources: get_custom_logo
Examples
Change Logo URL
Modify the logo’s URL to point to a custom location.
add_filter('get_custom_logo', 'change_logo_url', 10, 2);
function change_logo_url($html, $blog_id) {
$html = preg_replace('/(href=["\'])(.+?)(["\'])/', '$1' . 'https://example.com' . '$3', $html);
return $html;
}
Add Custom CSS Class to Logo
Add a custom CSS class to the logo.
add_filter('get_custom_logo', 'add_logo_css_class', 10, 2);
function add_logo_css_class($html, $blog_id) {
$html = str_replace('class="custom-logo"', 'class="custom-logo my-custom-class"', $html);
return $html;
}
Modify Logo Image Alt Attribute
Change the logo’s alt attribute to a custom value.
add_filter('get_custom_logo', 'change_logo_alt_attribute', 10, 2);
function change_logo_alt_attribute($html, $blog_id) {
$html = preg_replace('/(alt=["\'])(.+?)(["\'])/', '$1' . 'My Custom Alt Text' . '$3', $html);
return $html;
}
Remove Logo Link
Remove the hyperlink from the logo.
add_filter('get_custom_logo', 'remove_logo_link', 10, 2);
function remove_logo_link($html, $blog_id) {
$html = preg_replace('/<a.*?>(.*?)<\/a>/', '$1', $html);
return $html;
}
Add Custom Data Attribute to Logo
Add a custom data attribute to the logo.
add_filter('get_custom_logo', 'add_logo_data_attribute', 10, 2);
function add_logo_data_attribute($html, $blog_id) {
$html = str_replace('class="custom-logo"', 'class="custom-logo" data-custom-attribute="custom-value"', $html);
return $html;
}