- This topic has 7 replies, 4 voices, and was last updated 2 years, 2 months ago by David.
-
AuthorPosts
-
January 18, 2021 at 12:07 am #1623073Praveen
Hi guys,
I am planing to put banners in header and footer of website using hooks. But the challenge is the desktop banner is wide while the one on mobile is square.
Is there a way I can just display an image on Mobile and another one only on Desktop ?
I am fine adding two hooks for it, if needed.
January 18, 2021 at 6:49 am #1623556DavidStaffCustomer SupportHi there,
there is the
wp_is_mobile()
function that could be used to filter out which element to display, but is unreliable as server page caches may cache the desktop version and display that on mobile..Instead you would wrap your content in a
<div>
and use thehide-on-*
classes to show hide which one for each device. This article explains:https://docs.generatepress.com/article/responsive-display/#using-our-hide-on-classes
February 7, 2022 at 3:17 am #2107921ElvisI have used wp_is_mobile() in my custom themes extensively. However I am not a heavy cashing kinda guy so it might be that is the reason why it worked.
I am building a bottom nav bar/quicklinks toolbar for a mobile site version, and I am thinking to do it this way.
function prefix_mobile_quicklinks() { if ( wp_is_mobile() && function_exists( 'generate_after_footer' ) ) : do_action( 'mobile_quicklinks' ); endif; } add_action( 'generate_after_footer', 'prefix_mobile_quicklinks' );
It works on my local install, but I wonder. Is this the right way? Regarding caching, does generatepress use some caching I should worry about for this? Any other warnings? SEO?
Thanks.
February 7, 2022 at 3:23 am #2107930ElvinStaffCustomer SupportIt works on my local install, but I wonder. Is this the right way? Regarding caching, does generatepress use some caching I should worry about for this? Any other warnings? SEO?
There’s an option to cache CSS generated by the customizer but that’s it.
For SEO, the flags will depend on the added content. SEO’s usually about semantics. It’s about label attributes so if the things you’ll hook into that mobile_quicklinks are properly labels then it should be all good. 😀
February 7, 2022 at 4:37 am #2107990ElvisThanks Elvin,
regarding SEO I was thinking weather the changing DOM depending on mobile vs desktop, could have negative impact on SEO? Regardless of the semantics of that element.
Best,
ElvisFebruary 7, 2022 at 6:19 am #2108104DavidStaffCustomer SupportProbably a question for an SEO expert … but i can’t see there being an issue unless the intention was to replace the majority of the page content on a specific device. Its quite common to see DOM elements being injected for specific purposes such as UI
February 7, 2022 at 7:18 am #2108175ElvisThanks David
February 7, 2022 at 7:22 am #2108179DavidStaffCustomer SupportYou’re welcome
-
AuthorPosts
- You must be logged in to reply to this topic.