返回 wordpress CHILD 主题的正确路径



我很了解wordpress,但这是我第一次创建子主题。我意识到我需要在儿童主题中以不同的方式链接所有内容。

我通过使用"stylesheet_directly"让它适用于图像,如下所示:

  <img src="<?php bloginfo('stylesheet_directory'); ?>/images/icon.png" />

但是,我现在正在尝试在子主题的函数中将 javascript 文件排队.php我再次尝试使用"stylesheet_directory",但它返回了父主题的路径,而不是子主题。

为什么"stylesheet_directory"适用于我的子主题中的图像文件,但不适用于查询我的 functins 文件中的 javascript 文件?

这是我的职能。我还可以使用什么来返回正确的路径?

wp_enqueue_script( 'ga-slider', bloginfo('stylesheet_directory') . '/js/ga-slider.js');

我用了get_stylesheet_directory_uri()而不是你的bloginfo('stylesheet_directory').
前任。

wp_enqueue_script('script-name', get_stylesheet_directory_uri() . '/js/script.js', array('jquery'),2, true );

您可以使用get_stylesheet_directory_uri()作为子主题目录的相对路径。 get_stylesheet_directory()将返回子主题目录的绝对路径。

  • 文档:https://codex.wordpress.org/Function_Reference/get_template_directory

最新更新