在Wordpress中获取Wordpress儿童主题路径

时间:2021-08-26 07:44:35

I have a parent and child theme. In my child theme I declared a variable CHILD_DIR so I can add custom JS and CSS files to the my child theme's folder structure. I did this in my functions.php file in my child theme by doing this:

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

define( 'CHILD_DIR', get_stylesheet_directory_uri() );

This produces a URL which is what I want since I'm using it like this:

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

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

I also added some additional folders to my child theme which I want to use within a Wordpress page. I tried to do something like this:

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

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

I get an error since it's trying to provide a URL and I want a menu path to include the PHP and not try and make it an HTTP request. How can I define a path for the PHP instead of a URL to default to my child theme?

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

2 个解决方案

#1


29  

It's almost the same functions:

这几乎是相同的功能:

#2


0  

Main theme path : get_template_directory_uri();

主题路径:get_template_directory_uri();

Child Theme path : get_stylesheet_directory_uri(); or get_stylesheet_uri();

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

NOTE : Irrespective of calling js files or css files, For gettig the path of the theme or the path of the child theme we have to use the above functions.

注意:无论是调用js文件还是css文件,对于gettig主题的路径或子主题的路径我们都必须使用上述功能。

#1


29  

It's almost the same functions:

这几乎是相同的功能:

#2


0  

Main theme path : get_template_directory_uri();

主题路径:get_template_directory_uri();

Child Theme path : get_stylesheet_directory_uri(); or get_stylesheet_uri();

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

NOTE : Irrespective of calling js files or css files, For gettig the path of the theme or the path of the child theme we have to use the above functions.

注意:无论是调用js文件还是css文件,对于gettig主题的路径或子主题的路径我们都必须使用上述功能。