i created 4 header and 4 footer widgets using a site spesific plugin, the reason been that when i change themes, i keep all of my widgets. i created two files, one for the header widgets and one for the footer widgets. what i need to do now is to add these to the header and footer files.
at this stage i’m putting the following code manually in my header at the bottom after my header closing tag:
<? if ( is_front_page() ) : ?>
<?php get_sidebar( 'homepage' ); ?>
<?php endif ; ?>`
and the following code in my footer at the top:
<?php get_sidebar( 'footer1' ); ?>
How can i insert these codes automatically into my header and footer files from my plugin.
many thanks
Actually including that code in your theme template files is the only surefire way to include those widgets in various themes. It’s also the best to get them where you want them.
Alternatively, you could accomplish this using hooks, but that relies on your themes actually calling the hook, and in the proper location. The safest bets are the
get_header
andget_footer
hooks, which are called just before fetching the footer.php and header.php files, respectively.