In my Wordpress Theme, I have a "default" footer I use for every page, but I created a new footer I want to display only on the home page.
How do I hide the old footer and display my new footer on the home page?
There are a number of ways you could solve this, and none are more or less correct than the others. The way I would suggest is this;
Assuming you don't have it already, create front-page.php template and copy the content of page.php into it (if that's the template you're using).
Replace get_footer()
at the end of front-page.php with get_footer('home')
(assuming your new footer is called 'home-footer.php' (see the docs for more on that one)
As an alternatively, you could simply edit page.php and replace get_footer()
with something like:
if(is_front_page()) { //check if current page is the home page
get_footer('home');
} else {
get_footer();
}
Which utilises the is_front_page
conditional. (see conditional tags)
You can create custom template for homepage and call the new footer from that template using the function get_footer( $name )
, here $name
is the name of the new footer that you have created. Then select the homepage template from dashboard home page.
Open the header.php Edit the <body>
tag and make it <body <?php body_class(); ?>>
now in your homepage your body tag will render <body class="home">
then write css like:
body.home footer {
display: none;
}
add new footer in your homepage content