admin管理员组

文章数量:1387443

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 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?

Share Improve this question edited Jul 13, 2016 at 14:12 cjbj 15k16 gold badges42 silver badges89 bronze badges asked Jul 13, 2016 at 13:47 Davide De MaestriDavide De Maestri 1881 silver badge9 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 5

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;    
}

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' );

本文标签: theme developmentHow to change getcustomlogo() url