Skip to content
Advertisement

WordPress the_custom_logo doesn’t link on homepage

I’m using twentytwentyone-child theme and I want to link the custom_logo to the homepage even on the homepage.

But I can’t find any setting for that?

I read this: https://developer.wordpress.org/reference/functions/the_custom_logo/

And it says: “Displays a custom logo, linked to home unless the theme supports removing the link on the home page.

But if I look into the site-branding.php of the parent-theme I can only find this:

<?php if ( has_custom_logo() && $show_title ) : ?>
    <div class="site-logo"><?php the_custom_logo(); ?></div>
<?php endif; ?>

<div class="site-branding">

<?php if ( has_custom_logo() && ! $show_title ) : ?>
    <div class="site-logo"><?php the_custom_logo(); ?></div>
<?php endif; ?>

There is no if/else for linking it or don’t link it.

How can I do that?

Advertisement

Answer

This is happening because of this code in the parent theme’s functions.php:

add_theme_support(
    'custom-logo',
    array(
        'height'               => $logo_height,
        'width'                => $logo_width,
        'flex-width'           => true,
        'flex-height'          => true,
        'unlink-homepage-logo' => true,
    )
);

In your child theme’s functions.php, you can remove the theme support, and then add it back again, which you can do with this:

remove_theme_support( 'custom-logo' );

$logo_width  = 300;
$logo_height = 100;

add_theme_support(
    'custom-logo',
    array(
        'height'               => $logo_height,
        'width'                => $logo_width,
        'flex-width'           => true,
        'flex-height'          => true,
        'unlink-homepage-logo' => false,
    )
);

UPDATE: You’ll have to add this code to an action rather than using it directly in functions.php.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement