Short Answer: get_stylesheet();
从技术上讲,主题没有“slug”值。给定主题目录的名称就是您想要的名称。
get_template();
…将返回主题的目录名,
or the parent theme 如果当前主题是子主题。
get_option(\'stylesheet\');
将始终返回活动主题的目录名,无论它是否为子主题。
get_stylesheet();
将始终返回活动主题的目录名,无论它是否为子主题。此函数本质上是
get_option(\'stylesheet\');
, 除此之外,它还应用“样式表”过滤器。
function get_stylesheet() {
/**
* Filters the name of current stylesheet.
*
* @since 1.5.0
*
* @param string $stylesheet Name of the current stylesheet.
*/
return apply_filters( \'stylesheet\', get_option( \'stylesheet\' ) );
}
我不确定“样式表”过滤器的作用。看起来可能与自定义程序有关。
在绝大多数情况下,这三个功能会做同样的事情,但是get_stylesheet();
似乎是最安全的赌注。