WordPress主题制作

  1. 主页
  2. 文档
  3. WordPress主题制作
  4. 子主题(Child Theme)制作
  5. 子主题路径问题

子主题路径问题

如何引用子主题中的其他文件?

 

使用 get_stylesheet_directory() 和 get_stylesheet_uri() 函数,这两个函数都是指向“ 子主题 ” 目录 位置,这样就可以引用子主题目录里面的文件

这个例子使用 require_once 引入一个存放在你子主题目录中的文件。

require_once( get_stylesheet_directory(). '/my_included_file.php' );


即使父主题的functions.php如下代码,也是指向子主题路径。

wp_enqueue_style( 'twentynineteen-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );



如何引用父主题中的其他文件?


如何引用其他文件


子主题实质上就是一个独立的主题,不仅仅可以使用 style.css、functions.php 等文件,还可以增加其他的主题必备的文件和资源,例如:图片、样式、Javascript 等。当然,你要通过正确的链接地址引用到它们。


使用 get_stylesheet_directory() 和 get_stylesheet_uri() 函数,这两个函数都是指向“ 子主题 ” 目录 位置,这样就可以引用子主题目录里面的文件

这个例子使用 require_once 引入一个存放在你子主题目录中的文件。

 

require_once( get_stylesheet_directory(). '/my_included_file.php' );


即使父主题的functions.php如下代码,也是指向子主题路径。

wp_enqueue_style( 'twentynineteen-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );





这篇文章对您有用吗?

我们要如何帮助您?