admin管理员组文章数量:1122846
This is a rewritten post since the way I worded my old post totally confused everyone.
MikeSchinkel shows how he uses Include files in his theme's functions.php file In this Stackexchange post: Organizing Code in your WordPress Theme's functions.php File?
Example:
require_once('includes/my-file.php');
How would you write this php line if the file to include is inside a directory, inside the wp-content directory? Location: [wordpress install]/wp-content/new-directory/my-file.php
The only way I can think of is like this:
require_once( ABSPATH . '/wp-content/new-directory/my-file.php' );
Would this be the correct way?
This is a rewritten post since the way I worded my old post totally confused everyone.
MikeSchinkel shows how he uses Include files in his theme's functions.php file In this Stackexchange post: Organizing Code in your WordPress Theme's functions.php File?
Example:
require_once('includes/my-file.php');
How would you write this php line if the file to include is inside a directory, inside the wp-content directory? Location: [wordpress install]/wp-content/new-directory/my-file.php
The only way I can think of is like this:
require_once( ABSPATH . '/wp-content/new-directory/my-file.php' );
Would this be the correct way?
Share Improve this question edited Apr 13, 2017 at 12:37 CommunityBot 1 asked Jun 16, 2015 at 12:42 user3438958user3438958 4391 gold badge7 silver badges16 bronze badges2 Answers
Reset to default 9Including a file inside a subdirectory is the same as any other as long as you know the path to the file. Since it's possible to move the 'wp-content' directory, don't pass that part of the path to the require
statement; instead, use the WP_CONTENT_DIR
constant.
require_once WP_CONTENT_DIR . '/new-directory/my-file.php';
Also, you can leave out the parentheses since include
and require
are statements, not functions.
This also works:
require_once( ABSPATH . 'wp-content/new-directory/my-file.php' );
or
require_once get_stylesheet_directory() . '/my-file.php';
本文标签: Include files in functionsphp
版权声明:本文标题:Include files in functions.php 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736291566a1928751.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论