Archived topic
Mobile Menu Settings
11 replies · Started by HT on July 29, 2021
Hi There - I would like to turn off the Mobile version menu, logo, and ADV banner - when the user is getting accessed from a mobile device.
I have tried to disable everything related to mobile from Customize -> Layout
Pls can you advice
Hi there,
You can try hiding it from view on mobile through CSS.
Example:
@media(max-width:768px){
header#masthead {
display: none;
}
}
Or try this PHP snippet.
add_action( 'after_setup_theme','tu_remove_header' );
function tu_remove_header() {
if( wp_is_mobile() ){
remove_action( 'generate_header','generate_construct_header' );
}
}
I don't think wp_is_mobile() is as reliable because the best way to detect device is through client-side (css + javascript). But it's worth a try.
Will this just hide or disable the following items: What I'm trying to achieve is to reduce the code sending out to mobile devices by removing the following items.
Menu
Logo
ADV banner
Will this just hide or disable the following items: What I’m trying to achieve is to reduce the code sending out to mobile devices by removing the following items.
The first one will just hide it.
The second one, wp_is_mobile(), will not output the code, effectively reducing the code.
Thank you but I still see main menu in the mobile devices
Am I missing something
wp_is_mobile() is a bit of hit and miss sometimes - nothing related to the theme though.
What if you do this?
add_action( 'wp','tu_remove_header' );
function tu_remove_header() {
if( wp_is_mobile() ){
remove_action( 'generate_header','generate_construct_header' );
}
}
If that still doesn't work then the only solution might be CSS.
I will try this one?
It's up to you?
It didn't help (I think)
Hi there,
I just visited your site on a phone (Redmi Note 9s & Samsung J7 Pro - Chrome) and I don't see the section of the adv banner and the logo anymore.
I've gone beyond and plugged it on a pc to do a developer debug inspection and it doesn't render the codes just like you wanted. Does it still display on your mobile device?
I think I didn't explain it well.
Try this snippet to remove the navigation as well:
add_action( 'wp','tu_remove_header' );
function tu_remove_header() {
if( wp_is_mobile() ){
remove_action( 'generate_header','generate_construct_header' );
remove_action( 'generate_before_header', 'generate_add_navigation_before_header', 5);
}
}
Things to note:
1. wp_is_mobile() is not 100% reliable, as the function itself may not recognise all mobile devices. Or the client doesn't allow that info to be relayed to the server. In that case the function won't fire and the header will be displayed.
2. Server side page caching if enabled - may cache a Desktop or Mobile version of the page. If the server page caching is enabled and it doesn't support separate caches for mobile and desktop then you may find the header is still displayed or not displayed on any device.
3. Finally, but removing the <nav> element from the page isn't a good thing for Accessibility and you may want to take some SEO advice on the impact.