How to include a file using get_template_part() in a plugin?

get_template_part is a theme function. You can’t load plugin files with that function. Take a look at the source and you will notice the work is done by locate_template. Look at that source and you will see that it always loads from theme directories.

However much you may want to use get_template_part it is the wrong function.

You will need to include your files.

The reason, so it seems to me, for get_template_part is to allow themes to be extended– aka, to ease the creation of child themes. Plugins are not intended to be extended in that way so there is no need for get_template_part or for any plugin equivalent.

Leave a Comment