Using include() instead of get_footer()

Simple question. In a WordPress template, is there a reason I shouldn’t use include() and use get_footer() ?

Let’s say I want to have a sub folder in my template directory with all my components included. This seems to work okay but maybe I’m missing something.

Related posts

Leave a Reply

2 comments

  1. You shouldn’t use include() in your WordPress theme at all.

    The reason is that WordPress’ architecture is very pluggable – throughout core, plugins and themes, most components can interact with other components through actions and filters.

    While get_footer() might seem simple, the functions that it runs allow parts of your theme to be overridden. In this case, locate_template() allows a child theme to ship with a footer.php file in order to override the one set up by your main theme.

    In addition, get_footer() itself allows the flexibility of including multiple footer files in your WordPress theme so that you can call a slightly different footer on a particular template if you need to (by way of eg. get_footer('alternative') to call footer-alternative.php – which is then also overridable by a child theme).


    It’s worth noting that you should also ensure your footer template has a call to wp_footer() in it – ideally directly before the </html> tag. This goes back to what I mentioned above about actions and filters: in this case, any functions hooked to the footer by plugins or WordPress core (such as script includes) will get run as intended (incidentally, get_footer() itself also runs the get_footer action, which allows eg. a plugin to override which footer template is called – this is thus another reason to use get_footer()).

    Finally, in relation to not using include() in your theme at all, if you find yourself needing to include another template file that isn’t a header or footer, get_template_part() exists for that. While it sometimes may seem easier to just use native PHP functions rather than the wrappers the WordPress architecture provides, in the end doing it the ‘WordPress way’ means that your theme will interact better with plugins and future versions of Core, plus be more maintainable by others. And, you’ll probably help avoid causing weird bugs for yourself too!

  2. get_footer() (click link for source) doesn’t do anything further in the background rather than locate and include the file anyway.

    get_footer() then calls locate_template() which then calls load_template() which only does: require_once($template_file)

    It’s up to your preference but would recommend using get_footer() in case something does change in the future