Archived topic
How to configure a specific location for the logo image
11 replies · Started by mkjj on March 29, 2023
I try to use SVG logos whenever it is possible. For this I have to allow uploading SVGs to the media library. This can easily be done like so:
function cc_mime_types($mimes)
{
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'cc_mime_types');
However, since this simple snippet does not provide any validation it is better not to keep it active by default. Is it possible to use a URL in the customizer (or a snippet in the functions.php) instead of the default location? I could then upload the logo to the child theme folder. This would make it much easier to maintain. For me it makes more sense to have the logo combined with the child theme files. (The same is true for icons. I usually don't upload them to the media library.)
Thank you!
Hi there,
you can use the generate_logo filter. See here:
Sounds great! Thank you! I've just tested it, but it seems that I'm missing something. It doesn't change anything. I switched to my test server and added the filter to a original GP theme with no other plugins (and no caching) installed. Still no luck. I tried several variations.
For a specific page:
add_filter('generate_logo', function ($logo) {
if (is_page('who-we-are')) {
return 'URL';
}
else
return $logo;
});
For the front page:
add_filter('generate_logo', function ($logo) {
if (is_front_page()) {
return 'URL';
}
else
return $logo;
});
For the whole site:
add_filter('generate_logo', function () {
return 'URL';
});
Are you displaying the logo in the site header ? Or are you using the Navigation as header?
If you want me to check then share a link to the site :)
It's the default setting. I haven't even GP Premium activated on this site. Please note that this is just a test server. The site looks quite aweful. :-)
Ah theres a retina logo stuck in there.
Go to Settings > Site Identity - add a logo to the Retina field, publish changes, then delete that logo and publish the changes. That should get it out the way.
Wow, very impressive! :-) I would never have thought of that. That's just fine in this case. However, sometimes I just don't have a SVG. If I would use this filter for showing different images (like for a category, for example), I couldn't use an additional retina logo, could I?
No you couldn't use the retina logo, and to be honest i would not bother with retina logos now as most devices screens are x2 or higher DPR.
I absolutely agree when it comes to larger Retina displays like tablets or laptops. On Smartphones, however, a 2x resolution is often over the top. Many images are scaled down anyway. They won't look better significantly in 2x resolution. File size, on the other hand, can increase dramatically. With logos it's usually not a big deal, but fullwidth images can easily become huge.
Anyway, this solution is perfectly for me. It applies specifically to SVGs where the resolution does not matter.
For reference there is the generate_logo_output filter. With that you can rewrite the logos HTML if you need more control:
https://docs.generatepress.com/article/generate_logo_output/
Glad to be of help
Thanks David. It's really amazing how much we can do with GP in such elegant ways. :-)
Glad to be of help!