在Wordpress中获取Wordpress子主题路径


Get Wordpress Child Theme Path in Wordpress

我有一个父主题和子主题。在我的子主题中,我声明了一个变量child_DIR,这样我就可以将自定义的JS和CSS文件添加到子主题的文件夹结构中。我在孩子主题的functions.php文件中这样做:

define( 'CHILD_DIR', get_stylesheet_directory_uri() );

这会产生一个URL,这就是我想要的,因为我是这样使用它的:

wp_enqueue_script('custom', CHILD_DIR .'/custom.js', array( 'jquery' ));

我还为我的子主题添加了一些额外的文件夹,我想在Wordpress页面中使用这些文件夹。我试着做这样的事情:

require_once CHILD_DIR . '/Zend/Loader.php';

我遇到了一个错误,因为它试图提供一个URL,我想要一个包含PHP的菜单路径,而不是试图将其作为HTTP请求。我如何为PHP定义一个路径,而不是一个默认为我的子主题的URL?

它的功能几乎相同:

  • 父主题:get_template_directory()
  • 父主题或子主题:get_stylesheet_directory()

用于检索主题样式表目录URL

get_theme_file_uri() oR 
get_stylesheet_directory_uri()

用于检索绝对文件路径

get_stylesheet_directory() oR 
get_theme_file_uri()

主主题路径:get_template_directory_uri();

子主题路径:get_stylesheet_directory_uri();或get_stylesheet_uri();

注意:无论调用js文件还是css文件,为了获取主题的路径或子主题的路径,我们都必须使用以上函数。

define( 'CHILD_DIR',TEMPLATEPATH.'-child');

me函数,正在运行

你好,请更改url

旧:

background-image:url('<?php echo get_stylesheet_directory_uri() . "/images/bean.gif"; ?>') !important;

新增:

background-image:url('<?php echo get_template_directory_uri() . "/images/bean.gif"; ?>') !important;