php - Using include() instead of get_footer() -
simple question. in wordpress template, there reason shouldn't use include()
, use get_footer()
?
let's want have sub folder in template directory components included. seems work okay maybe i'm missing something.
you shouldn't use include()
in wordpress theme @ all.
the reason wordpress' architecture pluggable - throughout core, plugins , themes, components can interact other components through actions , filters.
while get_footer()
might seem simple, functions runs allow parts of theme overridden. in case, locate_template() allows child theme ship footer.php
file in order override 1 set main theme.
in addition, get_footer() allows flexibility of including multiple footer files in wordpress theme can call different footer on particular template if need (by way of eg. get_footer('alternative')
call footer-alternative.php
- overridable child theme).
it's worth noting should ensure footer template has call wp_footer() in - ideally directly before </html>
tag. goes mentioned above actions , filters: in case, functions hooked footer plugins or wordpress core (such script includes) run intended (incidentally, get_footer()
runs get_footer
action, allows eg. plugin override footer template called - reason use get_footer()
).
finally, in relation not using include()
in theme @ all, if find needing include another template file isn't header or footer, get_template_part() exists that. while may seem easier use native php functions rather wrappers wordpress architecture provides, in end doing 'wordpress way' means theme interact better plugins , future versions of core, plus more maintainable others. and, you'll avoid causing weird bugs too!