get_theme_file_path()

知更鸟 WordPress 开发评论65阅读模式

get_theme_file_path()函数可以用来引入主题中某个文件,也就是说你想找到主题中某个文件,可以用此函数来查找。
语法

get_theme_file_path( string $file = '' )

$文件 (字符串) (可选) 要在样式表目录中搜索的文件。默认值: ”文章源自知更鸟-https://zmingcx.com/get_theme_file_path.html

返回值文章源自知更鸟-https://zmingcx.com/get_theme_file_path.html

文件的路径文章源自知更鸟-https://zmingcx.com/get_theme_file_path.html

实例1文章源自知更鸟-https://zmingcx.com/get_theme_file_path.html

require_once get_theme_file_path() .'/inc/functions.php';

加载主题inc目录functions.php文件文章源自知更鸟-https://zmingcx.com/get_theme_file_path.html

实例2文章源自知更鸟-https://zmingcx.com/get_theme_file_path.html

if ( file_exists( get_theme_file_path( '/inc/functions.php' ) ) ) {
	require get_template_directory() . '/inc/functions.php';
}

判断主题inc是否有functions.php文件,有则加载这个文件。文章源自知更鸟-https://zmingcx.com/get_theme_file_path.html 文章源自知更鸟-https://zmingcx.com/get_theme_file_path.html

weinxin
我的微信
版权声明
本站原创文章转载请注明文章出处及链接,谢谢合作!
评论  0  访客  0
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定