Site logo

[Resolved] Disabled element “primary navigation” desktop only

Home Forums Support [Resolved] Disabled element “primary navigation” desktop only

Home Forums Support Disabled element “primary navigation” desktop only

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #2470717
    Erwin

    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?

    #2470842
    Ying
    Staff
    Customer Support

    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 );
    #2471294
    Erwin

    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.

    #2471300
    Fernando
    Customer Support

    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.

    #2471313
    Erwin

    Hi Fernando,

    Thanks, I followed your steps and added the snippet of Ying. But it is not working.

    #2471315
    Fernando
    Customer Support

    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

    #2471320
    Erwin

    Yes

    #2471322
    Fernando
    Customer Support
    #2471332
    Erwin

    FTP in functions.php of the child theme

    #2471335
    Fernando
    Customer Support

    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?

    #2471344
    Erwin

    I have removed the snippet from functions.php and added the plugin. Is this OK?

    #2471860
    Ying
    Staff
    Customer Support

    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

    #2472096
    Erwin

    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.

    #2474033
    Ying
    Staff
    Customer Support

    No Problem, glad to help 🙂

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.