HOME / BLOG / BLOG-POST

Can I override the values loaded by add_theme_support in function.php?

Problem:
I’m setting up a site based on the Twenty Seventeen theme and that theme includes in its function.php file a section to set the size of the custom-logo:
//code
add_theme_support( 'custom-logo', array(
 'width'       => 250,
 'height'      => 250,
 'flex-width'  => true,
) );
The site’s logo is 946 wide by 250 high. It is easy enough to load the 946 x 250 logo using the default configuration and then using the crop handles to increase the crop area from 250 to 946 (which does change the image name from logo.png to cropped-logo.png, but that’s a minor annoyance), BUT I would like to have the “Suggested image dimensions:” line that’s displayed when loading a new logo using the Site Identity screen to show 946 by 250 pixels rather than 250 by 250.
I could make the change in the function.php file, but that would go away with the first update, so I’d like to do something in the child theme’s function.php, but since the child function.php loads first, any values in that file are overwritten.

I did try adding

add_action( 'after_setup_theme', 'set_theme_custom_logo_size' );
 to the child function.php, but it fires before the parent function.php loads, so the parent settings still control the size.
Solutions:
I did find a solution – I need to add a priority to the add_action call.
The original add_theme_support call is in the function twentyseventeen_setup() in the parent function.php file, That function is called by the command:
add_action( 'after_setup_theme', 'twentyseventeen_setup' );
In my child theme, I had my own add_theme_support in a function that was called by the command:

add_action( 'after_setup_theme', 'set_theme_custom_logo_size' );
Since neither the parent call nor my call specified a priority, both calls were at the default priority of 10. Adding a priority of 11 to the child theme causes the parent function to fire first and then the child theme’s function (with the lower priority) will fire second.
I found the answer at a question regarding remove or update add_image_size on StackExchange.
The code below changes the size settings that show up in the Site Identity Customizing page:
// Add theme support for Custom Logo.
function set_theme_custom_logo_size() {
 add_theme_support( 'custom-logo', array(
  'height'      => 250,
  'width'       => 946,
  'flex-width' => true,
 ) );
}
add_action( 'after_setup_theme', 'set_theme_custom_logo_size', 11 );

 


about authors

Sandip Das

Web Developer

Once a legend said “Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” – Martin Fowler.



POST COMMENTS

Leave a Reply

Your email address will not be published. Required fields are marked *