- This topic has 9 replies, 2 voices, and was last updated 3 years, 3 months ago by David.
June 30, 2018 at 11:49 pm #612538Sally
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.
SallyGP Premium 1.6.2July 1, 2018 at 7:58 am #612764DavidStaffCustomer Support
this article explains the use of conditional tags with hooks:
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.July 1, 2018 at 11:09 am #612863Sally
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 ) ) ) : ?>
<?php endif; ?>
<?php if ( is_page( array( 11, 22, 33, 44 ) ) ) : ?>
<?php endif; ?>July 1, 2018 at 12:51 pm #612912DavidStaffCustomer SupportJuly 1, 2018 at 1:28 pm #612930Sally
You’re a legend! I really appreciate your help, David. Thank you 🙂July 1, 2018 at 1:37 pm #612931DavidStaffCustomer SupportJuly 2, 2018 at 8:45 pm #613914Sally
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 ) ) ) : ?>
<?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 ) ) ) : ?>
<?php endif; ?>July 3, 2018 at 3:59 am #614169DavidStaffCustomer Support
here is a list of the various conditionals.
Let me knowJuly 3, 2018 at 2:52 pm #614709Sally
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 🙂July 3, 2018 at 2:53 pm #614713
- You must be logged in to reply to this topic.