Home › Forums › Support › Image dimensions added to generate_logo_output filter not appearing in HTML
- This topic has 24 replies, 5 voices, and was last updated 4 years, 7 months ago by
Tom.
-
AuthorPosts
-
August 11, 2021 at 7:43 am #1892015
Brendan
I added the filter with the specified logo dimensions to my child theme functions file.
The rendered HTML didn’t change. My image dimensions don’t appear.
I tried adjusting the filter execution priority and still no luck. The following is my exact code, with logo dimensions 85w x 35h.
add_filter( 'generate_logo_output','tu_logo_atts', 10, 2 ); function tu_logo_atts( $output, $logo ) { printf( '<div class="site-logo"> <a href="%1$s" title="%2$s" rel="home"> <img width="85" height="35" class="header-image" src="%3$s" alt="%2$s" title="%2$s" /> </a> </div>', esc_url( apply_filters( 'generate_logo_href' , home_url( '/' ) ) ), esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ), esc_url( apply_filters( 'generate_logo', $logo ) ) ); }Notes:
1. Image dimensions appear on mobile. This is only happens on desktop.
2. Customizer width set to 85px wide.
3. I use Autoptimize CDN service, shortpixel (shouldn’t affect HTML).
4. Cleared Autoptimize cache (shouldn’t affect my HTML)
5. Use Cloudflare (also shouldn’t affect HTML)August 11, 2021 at 7:56 am #1892216David
StaffCustomer SupportHi there,
try the snippet Tom provides here:
https://generatepress.com/forums/topic/logo-does-not-have-explicit-width-and-height/#post-1762272
August 11, 2021 at 9:47 am #1892364Brendan
Hi David, thanks very much, appreciated.
Will this have to be removed in a subsequent update? Or will any future versions make it obsolete?
August 11, 2021 at 9:56 am #1892374Leo
StaffCustomer SupportYou can remove the snippet once our update fixes the issue 🙂
August 11, 2021 at 10:23 am #1892392Brendan
That snippet didn’t work either. Still no width=”x” height=”y” in the
tag. See the private URL.
August 11, 2021 at 11:30 am #1892466Leo
StaffCustomer SupportI actually just tested the code and it worked as expected.
Before: https://www.screencast.com/t/G8mqBP4bpL
After: https://www.screencast.com/t/xMKIxTcgM23Can you try clearing any caching plugin you might have?
August 11, 2021 at 11:38 am #1892471Brendan
Hi Leo, thanks for your reply. I’ll trying clearing caches and other things.
I don’t doubt the solution is correct, it follows the code in the header.php.
Something else might be causing a conflict. Will reply ASAP.
August 11, 2021 at 11:46 am #1892476Leo
StaffCustomer SupportMake sure the code is added using one of these methods:
Adding PHP: https://docs.generatepress.com/article/adding-php/August 11, 2021 at 11:49 am #1892478Brendan
Yep, added it to my child theme functions.php.
I recall adding some Google Analytics tracking.js to header.php in my child theme folder. I suspect that the latest GP header.php might differ from my version, updated many months ago.
I’ll try playing with that file and let you know.
At this point I’ve cleared autoptimize cache multiple times. I don’t think Cloudflare would be caching my HTML.
August 11, 2021 at 1:08 pm #1892547Brendan
My apologies, I had the wrong logo image! Didn’t intend to waste your time.
The problem image is the navigation logo. It’s lacking dimensions.
I saw a snippet for removing the link from the image. I only need to add dimensions. Here’s the code from gp-premium/menu-plus/functions/generate-menu-plus.php
I imagine there’s a way to add dimensions without hardcoding them? Note: Please preserve the ahref 🙂
echo apply_filters( 'generate_navigation_logo_output', sprintf( '<div class="site-logo sticky-logo navigation-logo"> <a href="%1$s" title="%2$s" rel="home"> <img src="%3$s" alt="%4$s" class="is-logo-image" /> </a> </div>', esc_url( apply_filters( 'generate_logo_href', home_url( '/' ) ) ), esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ), esc_url( apply_filters( 'generate_navigation_logo', $settings['sticky_menu_logo'] ) ), esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ) ) );August 11, 2021 at 5:02 pm #1892695Elvin
StaffCustomer SupportHi Brendan,
Try this:
add_filter( 'generate_navigation_logo_output', function($output){ $output = sprintf( '<div class="site-logo sticky-logo navigation-logo"> <a href="%1$s" title="%2$s" rel="home"> <img src="%3$s" alt="%4$s" class="is-logo-image" height="35" width="85"/> </a> </div>', esc_url( apply_filters( 'generate_logo_href', home_url( '/' ) ) ), esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ), esc_url( apply_filters( 'generate_navigation_logo', $settings['sticky_menu_logo'] ) ), esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ) ); return $output; });August 11, 2021 at 6:24 pm #1892736Brendan
Hi, we’re close. That filter successfully added dimensions.
The image source url is missing. For whatever reason sprintf value %3$s is empty
<img src="%3$s" alt="%4$s" class="is-logo-image" width="85" height="35" />It works if I hard code the image.
Should the function that gets the following IMG Url be declared in the filter? Perhaps the filter is running before the gp-premium plugin functions load?
esc_url( apply_filters( 'generate_navigation_logo', $settings['sticky_menu_logo'] ) ),August 11, 2021 at 9:30 pm #1892830Elvin
StaffCustomer SupportThe image source url is missing. For whatever reason sprintf value %3$s is empty
did you have a logo assigned on Appearance > Customize > Sticky navigation?
That’s where
%3$swill pull its logo from. If it’s empty, there will be no value for %3$sAugust 12, 2021 at 10:15 am #1893749Brendan
Hi,
Still not working. Now the image disappears on desktop.
Here are my customizer configurations:
Customizing->Layout->Primary Navigation->Navigation Logo Placement = Sticky
(If I select “Static” or “Sticky + Static”, the image URL doesn’t appear in thetag)
Customizing->Layout->Sticky Navigation = On, Transition = None, Hide when scrolling down = Checked
August 12, 2021 at 7:33 pm #1894068Elvin
StaffCustomer SupportStill not working. Now the image disappears on desktop.
Can you point us to what logo were you trying to applying this?
Is it for this one? https://share.getcloudapp.com/wbubeLGG
If it’s for the mobile logo only, you can use this filter instead.
generate_mobile_header_logo_outputExample:
-
AuthorPosts
- You must be logged in to reply to this topic.