Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override custom-logo parameters in WordPress child theme

Tags:

php

wordpress

I'm making a child theme based off of Shapely. In Shapely's functions.php, custom-logo support is declared.

/**
     * Add support for the custom logo functionality
     */
    add_theme_support( 'custom-logo', array(
        'height'     => 55,
        'width'      => 136,
        'flex-width' => true,
    ) );

In my child theme's functions.php, I tried writing:

function override_shapely_customlogo() {
    add_theme_support( 'custom-logo', array(
       'width'      => 168,
       'flex-height' => true,
    ) );
}
add_action( 'after_setup_theme', 'override_shapely_customlogo' );

But this doesn't appear to do anything.

Is there a way for a child theme to override custom logo support parameters?

like image 488
user3183717 Avatar asked Mar 03 '17 23:03

user3183717


People also ask

How do I resize a logo in WordPress?

First thing you need to do is navigate to Appearance » Customize and then click the 'Header' menu option. After that, click the 'Site Identity' menu option. Here you can easily adjust the size of your logo. All you have to do is move the 'Logo Width' slider to the left or right.


1 Answers

Took a bit of digging and I definitely encountered some false leads, but I got there. Turns out that you can absolutely override theme_support functions. However, your code has the exact same priority and action hook as Shapely's, so whichever code executes last wins out.

And (here's the bit that took some research) the functions.php of a child theme actually gets executed before the parent theme's:

[T]he functions.php of a child theme does not override its counterpart from the parent. Instead, it is loaded in addition to the parent’s functions.php. (Specifically, it is loaded right before the parent’s file.)

From the Codex, emphasis mine. Therefore, all we have to do is give your code a higher level of execution priority.

<?php
function override_shapely_customlogo() {
        add_theme_support( 'custom-logo', array(
             'width'      => 168,
             'flex-height' => true,
        ) );
}
add_action( 'after_setup_theme', 'override_shapely_customlogo', 11 );
?>

Edit: just wanted to add, the reason why I went with priority 11 here is that 10 is the default priority on add_action(): https://developer.wordpress.org/reference/functions/add_action/#parameters

like image 125
Leland Avatar answered Sep 30 '22 01:09

Leland