admin管理员组

文章数量:1417462

I am trying to include a template file into a loop i made in a shortcode, in a plugin. Everything shows up fine when the template is actually pasted into the loop, but to make things neat I want to separate it into it's own file.

I created a file called hi.php and it's located in a plugin subfolder called parts.

Here is the code I place in the loop, but it is not loading the template:

include plugins_url( '/parts/hi.php', __FILE__ );

I am trying to include a template file into a loop i made in a shortcode, in a plugin. Everything shows up fine when the template is actually pasted into the loop, but to make things neat I want to separate it into it's own file.

I created a file called hi.php and it's located in a plugin subfolder called parts.

Here is the code I place in the loop, but it is not loading the template:

include plugins_url( '/parts/hi.php', __FILE__ );

Share Improve this question edited Aug 7, 2019 at 17:09 Edegist asked Aug 7, 2019 at 16:54 EdegistEdegist 1331 silver badge10 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

I do it like this:

// Inclusion of additional php files
define( 'MYPLUG_DIR', plugin_dir_path( __FILE__ ) );

require_once( MYPLUG_DIR . 'hi.php' );

It lets you use that more easily if you have to include several files.

本文标签: phpHow to Include a Loop Template File in a Plugin