Replace head & footer with saved global rows

Hi,

I am creating this as a follow up on this thread -

http://forum.wpbeaverbuilder.com/support/q/use-saved-row-or-template-as-headerfooter/page/2/#post-93597

What I am aiming for is to have my saved global rows automatically added to any new page or post created within the website. I love the flexibility of the modules you can create with the BB page builder and would like to create my default head & footers in that way.

I am using BB theme & plugin, a step by step guide would really be appreciated.

Many thanks
Susanna

Hi Susanna,

To remove the BB Themes default Header and Footer globally. Load up the Customizer and navigate to Header > Header Layout and on the Layout option select None.

Do the same for the Footer.

Then you will want to create a page and call it something specific like “My Global Header” and 'My Global Footer". Open the builder on each of these pages and select the Blank template and add your global header module to the header page and global footer module to your footer page.

Once you have done this, open up the functions.php file from you BB child theme in your favourite code editor and add the following code:

// Adds my global header module my header
add_action('fl_before_header', 'my_global_header');
  function my_global_header(){
   echo do_shortcode('[fl_builder_insert_layout slug="YOUR PAGE SLUG GOES HERE"]');
 };
// Add my global footer to my footer
add_action('fl_after_content', 'my_global_footer');
  function my_global_footer(){
   echo do_shortcode('[fl_builder_insert_layout slug="YOUR PAGE SLUG GOES HERE"]');
 };

`

In the code be sure to replace YOUR PAGE SLUG GOES HERE with your global header page for the header snippet and the same for the footer snippet.

For example, if you named your header page “Global Header Page” then you will want to replace the YOUR PAGE SLUG GOES HERE with global-header-page.

Thanks,
Danny

Hi Danny,

I got really excited that you explained this all to me, so I gave it a go… But it all went wrong :frowning: and the site is now broken… My fault completely! But now need to see if I can get the old functions.php file back from a back up.

This is what I pasted into the child theme editor for the functions.php file

// Adds my global header module my header
add_action('fl_before_header', 'my_global_header');
  function my_global_header(){
   echo do_shortcode('[fl_builder_insert_layout slug="global-header"]');
 };

Is it because I did it directly into the editor in wordpress or because I didn’t change the parts where it says
my_global_header

Sorry for being such a pain!

Hi Susanna,

To resolve your issue, can you provide me with FTP access, so I can remove your changes.

In regards to your error, it is likely that you changed only once instance of the my_global_header, there are actually two. So if you change one, the other needs to match also.

Provide your FTP details and I can login and resolve the issue for you. Be sue to set your reply to private.

Thanks,
Danny

[Content Hidden]

Hi Suanna,

So I have removed the error and your site is now back up and running!

The issue was that the code wasn’t formatted correctly which you can see here - https://cloudup.com/cUoLfPEbUHx

I recommend you do the following:

1. Install and use a code editor if you don’t already. I recommend either Atom by GitHub or SubLime Text.

2. Then when you need to add or edit code from your child themes functions.php file. Do so via you FTP client. Navigate to the child theme directory and open the functions.php file through the FTP client by right-clicking and open in your favourite code editor.

3. This way if you happen to make a mistake that blows up your site, you can simply undo the changes, save the changes and then upload the file again. Which is what I have just done. :smiley:

I prefer this workflow over editing via the Editor in the WordPress Admin Dashboard because if you do make a mistake, like you did. You can not get back in to edit the file and so, you have to use FTP to correct the mistake. Hope this helps.

Thanks,
Danny

Great thanks Danny, I’ll give it another go! :slight_smile:

No problem and keep us posted, if this resolves your issue in regards to global header/footer.

Thanks,
Danny

YeY! I’ve done it! Thank you so much Danny. I will be saving this thread for future use!

Awesome! No problem at all Susanna, happy to help.

Thanks,
Danny

Hi Danny… Apologies for this but I have followed the same process to add a global row as a footer… Nothings broken but the footer just isn’t showing up.

Could you have a quick look for me to see what I have missed?

I added this code to the functions.php

 // Add global footer to footer
 add_action('fl_before_footer', 'global_footer');
   function global_footer(){
    echo do_shortcode('[fl_builder_insert_layout slug="global-footer"]');
  };

Many thanks
Susanna

Hi Susanna,

Can you provide temp admin access so I can take a closer look, please?

Thanks,
Danny

[Content Hidden]

Hi Susanna,

This was an issue on my part, so I apologise (need more coffee)! :smiley:

I have updated the code above to reflect the changes to correctly display your new global footer row.

I have also provided it below:

add_action('fl_after_content', 'my_global_footer');
  function my_global_footer(){
   echo do_shortcode('[fl_builder_insert_layout slug="YOUR PAGE SLUG GOES HERE"]');
 };

FYI: I was using the wrong action to insert the shortcode. The change above will resolve your issue.

Thanks,
Danny

Thanks Danny… Phew, it wasn’t me for once! Is the footer showing at your end?

Hi Susanna,

I never checked the footer action to be honest. The issue is that there is an if_statement on in the footer and the action I used was placed after that if_statement. This mean’t that if we set the Footer to None in the Customizer, the action we used wouldn’t work.

That’s why when I updated the hook to to use an action before that if_statement the footer row/module now displays. :smiley:

TLDR: The footer didn’t show for me, until I used the updated code.

Thanks,
Danny

Now I’m confused again… Its not showing at my end, should I now be doing something to activate it, or have you already done that?

Hi Susanna,

I logged into your FTP again and changed the code slightly. You were still using the old hook location of fl_before_footer instead of fl_after_content.

Can you check to see if this resolves your issue.

Thanks,
Danny

Right so can I just confirm, was this the final bit of code needed for the footer?

 // Add global footer to footer
 add_action('fl_after_content', 'global_footer');
   function global_footer(){
    echo do_shortcode('[fl_builder_insert_layout slug="global-footer"]');
  };

Yes. You were using the old code with the incorrect hook location. I changed it in your file to the correct one.

So if the row now displaying?

Thanks,
Danny