php - How to Include a Loop Template File in a Plugin

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

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745261642a4619236.html

相关推荐

  • php - How to Include a Loop Template File in a Plugin

    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

    3小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信