[Support request] Switch header (logo and nav menu) depending on page ID?

Home Forums Support [Support request] Switch header (logo and nav menu) depending on page ID?

Home Forums Support Switch header (logo and nav menu) depending on page ID?

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #612538
    Sally

    I’m using GP Pro and Elementor Pro and I’m building a site that needs to have a different site header (logo + nav menu) depending on where you are on the site.

    I have two header templates (call them header #1 and header #2) built in Elementor, and two menus (call them primary menu and alternative menu) built in WordPress (Appearance, Menus).

    I have used GP Hooks to insert the header template across the site. This header template contains a logo and the primary menu.

    What I need to do is show the second header (header #2), that has an alternative menu, on a number of pages on the site. I’ve created another header template in Elementor, and used the alternative menu I created in Appearance, Menus.

    But I’m not sure how to get it to appear on the pages I want. I’m guessing I need to do some kind of conditional PHP thing in GP Hooks to pick up the header #2 shortcode on the pages I want it to show on (and I’m guessing I’d need to add in page IDs for that), but I’m not proficient in PHP. If this is the right solution, is there a snippet or filter I can add?

    I have Code Snippets installed, so can add extra PHP safely that way, or alternatively, whatever else you recommend.

    Thank you so much in advance for any guidance you can give me. I can let you have an admin login to the site if necessary, but the site itself is behind a Coming Soon page at the moment.

    Warmly,
    Sally

    GP Premium 1.6.2
    #612764
    David
    Staff
    Customer Support

    Hi Sally,

    this article explains the use of conditional tags with hooks:

    https://docs.generatepress.com/article/using-hooks-conditional-tags/

    Something like this would be what you’re trying to achieve:

    <?php if ( is_page() && ! is_page( array( 11, 22, 33, 44 ) ) ) : ?>
        This Content will ONLY show in static pages, apart from those listed in array
    <?php endif; ?>
    
    <?php if ( is_page( array( 11, 22, 33, 44 ) ) ) : ?>
        This Content will ONLY show on the pages listed
    <?php endif; ?>

    Hoping early next week will be the release of GP 1.7 Beta which will make this sort of thing so much easier.

    #612863
    Sally

    Thank you so much, David.

    So would my entry into the Before Header Hook in GP Hooks look like this then, where the first one is the header template that I want to show on some page ids, and the second is the one I want to show on the rest of the pages?

    <?php if ( is_page() && ! is_page( array( 11, 22, 33, 44 ) ) ) : ?>
    [elementor-template id=”62″]
    <?php endif; ?>

    <?php if ( is_page( array( 11, 22, 33, 44 ) ) ) : ?>
    [elementor-template id=”2877″]
    <?php endif; ?>

    #612912
    David
    Staff
    Customer Support

    Hi Sally, that should be correct.

    #612930
    Sally

    You’re a legend! I really appreciate your help, David. Thank you πŸ™‚

    #612931
    David
    Staff
    Customer Support
    #613914
    Sally

    One more question on this, if I may.

    I’ve got this working perfectly for all pages (my code is copied below), where my elementor template shortcodes are the two different headers.

    I now need to replicate this exact same behaviour on my Blog archive and single pages on the same website, and once again, my PHP isn’t up to it. Are you able to help me with the PHP I need to show the right header on the blog archive and single pages too, please?

    <?php if ( is_page() && ! is_page( array( 2553, 1345, 38, 994, 715, 485, 711, 483, 2067, 34, 2031, 46, 50, 1590, 36, 1622, 1634, 40, 1646, 1657, 1668, 1382, 36, 6 ) ) ) : ?>
    [elementor-template id=”1734″]
    <?php endif; ?>

    <?php if ( is_page( array( 2553, 1345, 38, 994, 715, 485, 711, 483, 2067, 34, 2031, 46, 50, 1590, 36, 1622, 1634, 40, 1646, 1657, 1668, 1382, 36, 6 ) ) ) : ?>
    [elementor-template id=”2877″]
    <?php endif; ?>

    #614169
    David
    Staff
    Customer Support
    #614709
    Sally

    Yep, that did the trick. Thanks to your original PHP I was able to figure out what to do with the code on the article you linked to.

    Much appreciated, as always πŸ™‚

    #614713
    David
    Staff
    Customer Support

    You’re welcome Sally, glad to hear you figured it out πŸ™‚

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