If you’re creating WordPress themes you surely came across the get_template_part function at one point or another. It’s one of those hidden gems inside of WordPress that don’t get the attention they deserve. Let’s change that.
The get_template_part function is essentially a PHP include or require, on steroids:
- It already knows where your theme is located and it will look for the requested file in that theme’s directory
- It doesn’t issue a warning or fatal out if the requested file does not exist
- It can search for other suitable files, if the requested one is not found
- It knows about child themes and parent themes
Long story short, the get_template_part function allows you to break your theme down into smaller templates (or template parts), which can be reused across your other templates.
Although get_template_part is similar to a PHP include or require, you should not use it to include things like your theme options code, sidebars registration, custom widgets, etc. The get_template_part function should only be used to get template parts.
Let’s start off with some basic examples.














