Debugging WordPress Template Part Loading

Template parts are a fundamental part of building WordPress themes but sometimes it can be difficult to find out why a given template part is or isn’t loading.

The latest version of Query Monitor makes debugging template part loading easier by exposing the list of any template parts that were not loaded, in addition to those that were. Here’s a screenshot of it in action:

Screenshot of the Template Parts section of the Template panel in Query Monitor

What this allows you to do is to see the value of the $slug and $name parameters that were passed to get_template_part() when an unsuccessful request for a template part was made. Query Monitor will show you the file name and line number where the call was made, so you can find it easily and investigate if necessary, or if you’ve got clickable stack traces enabled you can just click it to be taken straight there.

Note that this feature requires WordPress 5.2 or later, as it uses a new hook that was introduced in that version.

I hope this feature is useful to you! I’ve certainly been finding it useful myself.

2 thoughts on “Debugging WordPress Template Part Loading”

  1. Hey John, this is Marine from WPML plugins.
    I’d like to connect with you to talk about a few things, what’s the best way to reach out?



Leave a comment