在我的WordPress中,我有一个包含1500行代码的functions.php文件.
大部分代码来自我编写的程序,该程序连接到API并将数据从WordPress发送到它.我不是WordPress开发人员,所以我不知道这是否可行.你可以制作一个不同的文件来保持functions.php干净,然后在functions.php中包含外部文件吗?
Bac*_*ngh 10
是的,您可以在functions.php中包含外部文件
require_once(get_template_directory().'anyfilename.php');
小智 6
您可以使用以下任一方法在 functions.php 中包含外部文件
require_once();
Run Code Online (Sandbox Code Playgroud)
否则你可以使用
include_once();
Run Code Online (Sandbox Code Playgroud)
这两者之间的区别在于,如果找不到文件, require 将发出致命错误,然后停止执行文件的其余部分,而 include 只会发出警告,但会继续执行文件。
小智 5
如果您使用的是儿童主题,但找不到包含路径的路径:
请尝试以下操作:
include_once( get_stylesheet_directory() .'/xxxx/anyfilename.php');
检查get_stylesheet_directory()以查看您的子主题路径。
| 归档时间: |
|
| 查看次数: |
15139 次 |
| 最近记录: |