GeneratePress with Elementor logo

Elementor – GeneratePress – GP Premium – AnyWhere Elementor – Switch Site Header

If you find this tutorial to be helpful and of use, consider buying Sniffle Valve a coffee  

For help with the content presented in this tutorial, book a one-on-one online training session

UPDATE: 29 JULY 2017

At the request of one of the commenters, I have added the code to use four different headers, one for each of four specific pages.

In the code examples, I have the 4 pages: sample-page, text-flow, two-buttons, and nested-sections. Note that the preceding are the slugs for these pages. You will also need to replace the IDs with your own. The first four items are for the specific pages while the last item is what will appear on all the other pages.

<?php 
 if ( is_page( 'sample-page' ) ) {
 echo do_shortcode( '[INSERT_ELEMENTOR id=103]' );
 } else 
if ( is_page( 'text-flow' ) ) {
 echo do_shortcode( '[INSERT_ELEMENTOR id=266]' );
 } else 
if ( is_page( 'two-buttons' ) ) {
 echo do_shortcode( '[INSERT_ELEMENTOR id=269]' );
 } else 
if ( is_page( 'nested-sections' ) ) {
 echo do_shortcode( '[INSERT_ELEMENTOR id=272]' );
 } else {
echo do_shortcode( '[INSERT_ELEMENTOR id=276]' );
}
 ?>
Four different headers

This video shows you how to easily switch the site header depending upon which page is being displayed.

It requires the following plugins:

Elementor: https://wordpress.org/plugins/elementor

GeneratePress Premium: https://generatepress.com/premium

AnyWhere Elementor: https://wordpress.org/plugins/anywhere-elementor

You will also need this PHP code to past into the Before Header Content hook location within GP Hooks, which is a part of the GP Premium plugin.

<?php 
 if ( is_page( array( 'services', 'about' ) ) ) {
 echo do_shortcode( '[INSERT_ELEMENTOR id=xxx]' );
 } else {
 echo do_shortcode( '[INSERT_ELEMENTOR id=xxx]' );
 }
 ?> 

Individual posts may also be targeted with this method.

 <?php 
 if ( is_single( array( 'Post One', 'Post Two' ) ) ) {
 echo do_shortcode( '[INSERT_ELEMENTOR id=xxx]' );
 } else {
 echo do_shortcode( '[INSERT_ELEMENTOR id=xxx]' );
 }
 ?> 

Note that you will also have to adjust the id=xxx to match your own id values as well as the names of the pages or posts.

15 thoughts on “Elementor – GeneratePress – GP Premium – AnyWhere Elementor – Switch Site Header

  1. How about posts instead of pages? I have three pages I don’t want a created template to show up on but I want it at the bottom of every post…….

    I am assuming that you are instructing me to put in the short code id where it says, “not a valid elementor page” ?

    • Good catch Brad! 🙂
      I didn’t notice that on the front end of the site, that the shortcode was not displayed, as it looked fine in the WP Editor. It is trying to display shortcode, which of course, isn’t there, and that is not what I intended. I am going to have to test some other code display plugins and adjust accordingly.
      Yes, you would enter the Anywhere Elementor shortcode in those locations.
      I haven’t tested posts yet but I’ll do some testing and update the page as required.
      Cheers!
      Lyle

  2. You speak slow and easy, thats important for us foreigners. I just found your videos and your site extremely useful and interesting.
    Thank you for another really good video.
    Thanks.

  3. Hi Lyle.
    When I follow your video “Elementor – GeneratePress – GP Premium – AnyWhere Elementor – switch site header” I see when you hover over the list of pages you get the Elementor Id, that you put in the GP Hooks to switch header. When I try to do the same the Id doesn’t show up when I hover over the list of pages? How do I get it? What have I missed?

    Ralf.

    • Hi Ralf,

      Thank you for pointing this out 🙂 I should have mentioned that I was using a plugin that displays the post, page, etc. IDs in the admin listings. You can also get the ID by hovering over the title and looking in the lower left corner of your browser at the link that is displayed; the ID will be the number after post.php?post=
      The plugin that I used is this one from the WP plugin repository: https://wordpress.org/plugins/wpsite-show-ids/
      Just install and activate and the IDs will show up in a new column in the page, post, etc. listing.

      Cheers!
      Lyle

  4. How could I use this feature for the GeneratePress free theme, to create a Header on the Elementor and replace what comes standard with the theme?

    • Hi André,

      To do this using just the free GP theme, you would need to use a child theme and then add the PHP code in the header.php file that you would copy from the GP theme. I will be creating a video soon on how to do this as there are many who, for various reasons, cannot acquire the GP Premium plugin.

      Cheers!
      Lyle

  5. Is there anyway to have more than 2 headers? I am building a website where I need 3 or 4 different headers.

    Thanks
    Brandon

      • Brandon –
        I have updated the page to add the conditional code to have 4 different headers, each on a specific page. I have to add it there as the code is PHP so I can’t put it in the Comments. In the code examples, I have the 4 pages: sample-page, text-flow, two-buttons, and nested-sections. Note that the preceding are the slugs for these pages. You will also need to replace the IDs with your own. The first 4 items are for the specific pages while the last item is what will appear on all the other pages.

Leave a Comment