Site logo

Archived topic

Best practice for site assets

6 replies · Started by Steven on March 9, 2020

Viewing posts 1–7 of 7

Wondering what's recommended for storing site assets like logo, fav icon, footer background images, etc. We would prefer not to store them in the Media gallery so editors can't mess with them. We thought about storing them in our child theme folder, but the GeneratePress customizer appears to only allow you to browse to the Media gallery. There's no option to manually paste the location. Is there a way to override the logo and fav icon locations using something in a child theme functions.php file? Thanks for any tips you can pass along.

Hi there,

The controls in the Customizer will only look in the Media Library.

For the favicon, you can simply upload a favicon.ico file into the root directory of the site.

For the site logo, you can use a filter if you'd like:

add_filter( 'generate_logo', function() {
    return 'URL TO YOUR LOGO';
} );

Let me know if you need more info :)

Removing the favicon setting in GP customizer and placing the file in the root of the site worked.

I tried the filter in the functions.php and removed the logo settings in the GP customizer. It didn't work though. So I experimented with selecting an image from the Media gallery for the following logo settings in the GP customizer:

Customizing > Layout > Header > Logo
Customizing > Site Identity > Logo
Customizing > Layout > Sticky Navigation > Sticky Navigation Logo

So the filter in the functions.php seems to override the settings in the customizer, but you need an image specified in the customizer - even if it's not used - in order for the logo to be rendered on the page correctly. The odd thing is, the logo was being loaded with the page according to dev tools - it just wasn't being displayed. It looks like the mobile logo isn't being updated though. Is there a way to ensure it gets the correct logo instead of the placeholder image?

Maybe an enhancement request would be to allow the override option without the need to specify a placeholder image in the customizer. I know it will cause confusion in the future if someone wants to update the logo file as the first place they'll look is under the Appearance section of the site.

In case it helps, here are some related settings in the GP customizer:

Customizing > Layouts > Header
Use Navigation as Header: selected
Mobile Header: On
Branding Type: Logo
Logo: placeholder image (same as fav icon and different than actual horizontal logo we'd like displayed)
Sticky: On
Hide when scrolling down: selected

Here's our functions.php code:

//Set logo URL    
add_filter( 'generate_logo', function() {
    return '/cob-logo.svg';
} ); 

You can actually filter the Customizer options directly.

For example:

add_filter( 'theme_mod_custom_logo', function() {
    return 123; // Needs an image ID, which means the image needs to at least be in the library.
} );

add_filter( 'option_generate_menu_plus_settings', function( $settings ) {
    $settings['mobile_header_logo'] = 'URL TO LOGO';
    $settings['sticky_navigation_logo'] = 'URL TO LOGO';

    return $settings;
} );

Might be worth trying :)

So I tried the following and it appears to be working as best I can tell. Thanks for the great support, as always!

//Set custom logo location    
add_filter( 'generate_logo', function() {
    return '/logo.svg';
} );    
add_filter( 'option_generate_menu_plus_settings', function( $settings ) {
    $settings['mobile_header_logo'] = '/logo.svg';
    $settings['sticky_navigation_logo'] = '/logo.svg';

    return $settings;
} );

You're welcome :)

This archived topic is closed to new replies.