Template part vs Sidebar (differences)

I want to add a hard coded footer into the… footer.php of my site. This doesn’t need to be “dynamic” (adding and removing widgets), it will be something standard like info about the site and specific links.

If I am correct this can be done either by get_template_part( 'template-parts/', 'infofooter' );

or by get_sidebar( 'infofooter' );

In the second case I just have to name my file sidebar-infofooter.php

Are both methods equally valid? What is the difference between a (non-dynamic) sidebar and a template part? Is it that a sidebar usually includes widgets?

1 Answer
1

The get_sidebar($name); function loads sidebar template file sidebar-{$name}.php if no name in the prentacies is specified it loads the sidebar.php file.

get_sidebar() and get_template_part() are almost identical, at the end they call locate_template() function that take care of loading from files.

The only difference is the hook fired. If you use get_sidebar() for all your widget areas you can target them all later with get_sidebar hook if needed.

So both options are equally valid in terms of code. They differ in semantics as sidebar usually contains a dynamic_sidebar() area inside the template.

Leave a Comment