WP Themehat

wordpress get_footer

Todays Episode Is How get_footer() Function Works. You Guys Already Know About The Template Files Of WordPress. footer.php Is One One Them. For Including That footer.php File Into Another File Like Index.php Just Call The Function get_footer(). The Content Of The footer.php Will Come In Your Index.php File Or Any Other File That You Want To Include. Not Only That, You Might Want That In Different Page Of Your Website You Want Different Footer. No Matter get_footer() Will Do That Job Also. get_footer(string $name = null ) Its Support A Parameters Which Is Optional. Suppose You Need A Different Footer In Your 404 Page Or In Your Home Page Or Any Other Page. You Can Write Like:

if ( is_home() ) :
    get_footer( 'home' );
elseif ( is_404() ) :
    get_footer( '404' );
else :
    get_footer();
endif;

The file names for the home and 404 footer should be footer-home.php and footer-404.php respectively.

Behind The Scene Of get_footer();

function get_footer( $name = null ) {
    /**
     * Fires before the footer template file is loaded.
     *
     * @since 2.1.0
     * @since 2.8.0 $name parameter added.
     *
     * @param string|null $name Name of the specific footer file to use. null for the default footer.
     */
    do_action( 'get_footer', $name );
 
    $templates = array();
    $name      = (string) $name;
    if ( '' !== $name ) {
        $templates[] = "footer-{$name}.php";
    }
 
    $templates[] = 'footer.php';
 
    locate_template( $templates, true );
}

Learn about get_header

Exit mobile version