The generate_logo_output
filter allows us to alter the HTML of our logo.
Setting a Width and Height
If want want to set a specific width and height in the logo HTML output:
add_filter( 'generate_logo_output','tu_logo_atts', 10, 2 ); function tu_logo_atts( $output, $logo ) { printf( '<div class="site-logo"> <a href="%1$s" title="%2$s" rel="home"> <img width="999" height="999" class="header-image" src="%3$s" alt="%2$s" title="%2$s" /> </a> </div>', esc_url( apply_filters( 'generate_logo_href' , home_url( '/' ) ) ), esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ), esc_url( apply_filters( 'generate_logo', $logo ) ) ); }
Adding a New Class
If we want to add a new class to our logo container:
add_filter( 'generate_logo_output', 'tu_logo_class', 10, 3 ); function tu_logo_class( $output, $logo_url, $html_attr ) { printf( '<div class="site-logo MY-CUSTOM-CLASS"> <a href="%1$s" title="%2$s" rel="home"> <img %3$s /> </a> </div>', esc_url( apply_filters( 'generate_logo_href' , home_url( '/' ) ) ), esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ), $html_attr ); }
Open a New Window
If we want our logo to open in a new window:
add_filter( 'generate_logo_output', 'tu_logo_target', 10, 3 ); function tu_logo_target( $output, $logo_url, $html_attr ) { printf( '<div class="site-logo"> <a href="%1$s" title="%2$s" rel="home" target="_blank" rel="noopener"> <img %3$s /> </a> </div>', esc_url( apply_filters( 'generate_logo_href' , home_url( '/' ) ) ), esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ), $html_attr ); }
Remove the Logo Link
If we don’t want a link surrounding our logo:
add_filter( 'generate_logo_output', 'tu_no_logo_link', 10, 3 ); function tu_no_logo_link( $output, $logo_url, $html_attr ) { printf( '<div class="site-logo"> <img %1$s /> </div>', $html_attr ); }