I need to change default WordPress get_custom_logo() generated url because I need to link to the main multi-site site instead of single site. Is there any filter to change this function?


I solved using this filter:

add_filter( 'get_custom_logo',  'custom_logo_url' );
function custom_logo_url ( $html ) {

$custom_logo_id = get_theme_mod( 'custom_logo' );
$url = network_site_url();
$html = sprintf( '<a href="%1$s" class="custom-logo-link" rel="home" itemprop="url">%2$s</a>',
        esc_url( $url  ),
        wp_get_attachment_image( $custom_logo_id, 'full', false, array(
            'class'    => 'custom-logo',
        ) )
return $html;    
| improve this answer | |

Here's an alternative solution:

function update_logo_url( $html ) {
    $site_url = get_site_url();

    return str_replace( $site_url, esc_url( 'https://your.url' ), $html );

add_filter( 'get_custom_logo', 'update_logo_url' );
| improve this answer | |
  • Thank you for answering. If at all possible, try to include a bit of information explaining why your answer works and what's happening in the code. – Tony Djukic Apr 16 at 7:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.