[Resolved] Best practice for site assets

Home Forums Support Best practice for site assets

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1189975
    Steven

    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.

    #1190223
    Tom
    Lead Developer
    Lead Developer

    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 🙂

    #1191147
    Steven

    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.

    #1191159
    Steven

    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';
    } ); 
    #1191328
    Tom
    Lead Developer
    Lead Developer

    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 🙂

    #1191997
    Steven

    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;
    } );
    #1192394
    Tom
    Lead Developer
    Lead Developer
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.