Archived topic
Disabled element "primary navigation" desktop only
13 replies · Started by Erwin on December 22, 2022
Hello, I have disabled the primary navigation element for one page specific. I would like to disable this for desktop only and keep the hamburger navigation for the mobile version. What would you recommend?
Hi Erwin,
Try this snippet and replace the 100 with your layout element's ID.
add_filter( 'generate_element_display', function( $display, $element_id ) {
if ( 100 === $element_id && wp_is_mobile()) {
$display = false;
}
return $display;
}, 10, 2 );
Hi Ying,
Thank you for your reply.
What element do you mean? For the record, I don't want to show the primary navigation on a specific page (what is easy, I just disabled the "primary navigation" element at the page settings". But I do want to show this primary navigation on the mobile phone.
So what do you mean with my layout element ID?
Thanks in advance.
Hi Erwin,
Ying is referring to creating a Layout Element to do this. Reference: https://docs.generatepress.com/article/layout-element-overview/
Specifically,
1. Create a Layout Element.
2. Disable the Primary Navigation in the Element: https://docs.generatepress.com/article/layout-element-overview/#disable-element
3. Set it to display on the page you want the Navigation hidden.
4. Add the code here as instructed by Ying: https://generatepress.com/forums/topic/disabled-element-primary-navigation-desktop-only/#post-2470842
Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
Getting the Element ID(This is what Ying means with regards to the Layout ID): https://share.getcloudapp.com/YEuDdrnQ
Hope this clarifies.
Hi Fernando,
Thanks, I followed your steps and added the snippet of Ying. But it is not working.
Can you provide Admin Login credentials?
We'll check why it isn't working.
Please use the Private Information field for this: https://docs.generatepress.com/article/using-the-premium-support-forum/#private-information
Yes
How did you add the snippet here?: https://generatepress.com/forums/topic/disabled-element-primary-navigation-desktop-only/#post-2470842
FTP in functions.php of the child theme
I see. Can you try adding it through plugin Code Snippets first so we can see it on the backend and see if it's working?
I have removed the snippet from functions.php and added the plugin. Is this OK?
Hi Erwin,
I'm not able to see the snippet or the plugin in admin as your site is a multi-site install and the account doesn't have super admin access.
But I checked the layout element, and the ID is 1156, so you need to replace the 100 with 1156 in my code
Hi Ying,
Believe it or not, I definitely forgot to add the ID. Very stupid, apologies. (again) Thank you so much for your help.
Happy Holidays.
No Problem, glad to help :)
