The get_custom_logo_image_attributes WordPress PHP filter allows you to modify the attributes of a custom logo image.
Usage
add_filter('get_custom_logo_image_attributes', 'your_custom_function', 10, 3); function your_custom_function($custom_logo_attr, $custom_logo_id, $blog_id) { // your custom code here return $custom_logo_attr; }
Parameters
$custom_logo_attr
(array) – The custom logo image attributes.$custom_logo_id
(int) – The custom logo attachment ID.$blog_id
(int) – The ID of the blog to get the custom logo for.
More information
See WordPress Developer Resources: get_custom_logo_image_attributes
Examples
Add a custom class to the logo
Add a custom class ‘my-custom-logo’ to the logo image.
function add_custom_logo_class($custom_logo_attr, $custom_logo_id, $blog_id) { $custom_logo_attr['class'] = 'my-custom-logo'; return $custom_logo_attr; } add_filter('get_custom_logo_image_attributes', 'add_custom_logo_class', 10, 3);
Add an alt attribute to the logo
Add an alt attribute ‘Company Logo’ to the logo image.
function add_custom_logo_alt($custom_logo_attr, $custom_logo_id, $blog_id) { $custom_logo_attr['alt'] = 'Company Logo'; return $custom_logo_attr; } add_filter('get_custom_logo_image_attributes', 'add_custom_logo_alt', 10, 3);
Add a custom width and height to the logo
Set a custom width and height (200px and 50px) for the logo image.
function custom_logo_dimensions($custom_logo_attr, $custom_logo_id, $blog_id) { $custom_logo_attr['width'] = '200'; $custom_logo_attr['height'] = '50'; return $custom_logo_attr; } add_filter('get_custom_logo_image_attributes', 'custom_logo_dimensions', 10, 3);
Add a custom data attribute to the logo
Add a custom data attribute ‘data-custom’ with the value ‘example’ to the logo image.
function add_custom_data_attribute($custom_logo_attr, $custom_logo_id, $blog_id) { $custom_logo_attr['data-custom'] = 'example'; return $custom_logo_attr; } add_filter('get_custom_logo_image_attributes', 'add_custom_data_attribute', 10, 3);
Remove the srcset attribute from the logo
Remove the srcset attribute from the logo image.
function remove_logo_srcset($custom_logo_attr, $custom_logo_id, $blog_id) { unset($custom_logo_attr['srcset']); return $custom_logo_attr; } add_filter('get_custom_logo_image_attributes', 'remove_logo_srcset', 10, 3);