Php 为什么它被称为get_template_directory和get_stylesheet_directory?
我是Wordpress的新手,我把Nisarg的子主题改为我的孩子主题caribia。现在,在我的themes functions.php中,我想添加一些样式和脚本,因此我有以下代码(可以正常工作): 所以它被称为wp_enqueue_脚本很好,但是它应该只用于脚本,对吗?为什么没有一个名为wp_enqueue_styles的函数 另一个问题是,为什么函数get_template_directory()返回父主题的URL?get_stylesheet_directory()返回我当前的主题目录,我想get_stylesheet_directory()应该返回我的主题/样式或我的主题/cssPhp 为什么它被称为get_template_directory和get_stylesheet_directory?,php,wordpress,themes,Php,Wordpress,Themes,我是Wordpress的新手,我把Nisarg的子主题改为我的孩子主题caribia。现在,在我的themes functions.php中,我想添加一些样式和脚本,因此我有以下代码(可以正常工作): 所以它被称为wp_enqueue_脚本很好,但是它应该只用于脚本,对吗?为什么没有一个名为wp_enqueue_styles的函数 另一个问题是,为什么函数get_template_directory()返回父主题的URL?get_stylesheet_directory()返回我当前的主题目录,
谢谢有一个叫做
wp\u enqueue\u风格的函数
是的,我知道。我在上面的代码中同时使用了wp_enqueue_样式和wp_enqueue_脚本。但是add_action($tag,…)方法只有标记“wp_enqueue_scripts”,而没有一个名为“wp_enqueue_styles”的方法。。。就是这样,但是我绝对不理解关于样式表目录和模板目录的第二个问题。get_stylesheet_directory()是wp中的一个自定义函数。它设计用于作者支持子主题的父主题,因此如果安装了子主题,该函数将返回子主题的目录。一个用途是将css文件排队,但它也用于其他用途。如果文件/路径仅严格位于父主题中,则可以使用template\u目录返回此文件。有一个名为wp\u enqueue\u style
的函数,我知道。我在上面的代码中同时使用了wp_enqueue_样式和wp_enqueue_脚本。但是add_action($tag,…)方法只有标记“wp_enqueue_scripts”,而没有一个名为“wp_enqueue_styles”的方法。。。就是这样,但是我绝对不理解关于样式表目录和模板目录的第二个问题。get_stylesheet_directory()是wp中的一个自定义函数。它设计用于作者支持子主题的父主题,因此如果安装了子主题,该函数将返回子主题的目录。一个用途是将css文件排队,但它也用于其他用途。如果文件/路径仅严格位于父主题中,则可以使用template_目录返回该文件/路径。
function caribia_enqueue_scripts() {
$parent_style = 'parent-style';
wp_enqueue_style($parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style('child-style',
get_stylesheet_directory_uri() . '/style.css', array( $parent_style )
);
wp_enqueue_script('caribia', get_template_directory_uri() . '/js/caribia.js');
}
add_action( 'wp_enqueue_scripts', 'caribia_enqueue_scripts' );