Wordpress 使用样式表检查主题是否为子主题
Wordpress check if theme is a child using stylesheet
我想使用样式表检查特定主题是否为子主题。
例如:
$childBoolean = functionHere( 'twentyfifteen' );
我需要某种功能来检查特定主题是否为子主题。它应该 return 一个布尔值。
那么,有没有一个函数可以检查它?有什么想法吗?
谢谢
您可以使用 is_child_theme()
检查当前主题是否是另一个主题的子主题。函数文档在这里:https://codex.wordpress.org/Function_Reference/is_child_theme
如果您知道如何使用此代码,它可能会有用:
1486 // Look in a parent theme first, that way child theme CSS overrides.
1487 if ( is_child_theme() ) {
1488 $template_uri = get_template_directory_uri();
1489 **$template_dir = get_template_directory();**
1490
1491 foreach ( $editor_styles as $key => $file ) {
1492 if ( $file && file_exists( "$template_dir/$file" ) ) {
1493 $stylesheets[] = "$template_uri/$file";
1494 }
1495 }
1496 }
(来自:wp-includes/theme.php,通过 AllysonSouza 评论中的 link。
我想您应该能够使用其中一些 php 命令或拉取变量来获取模板目录名称,这几乎总是主题名称。
$template_dir 或 get_template_directory();
此外,可能会使用以下内容:
128 /**
129 * Whether a child theme is in use.
130 *
131 * @since 3.0.0
132 *
133 * @return bool true if a child theme is in use, false otherwise.
134 **/
135 function is_child_theme() {
136 return ( **TEMPLATEPATH** !== STYLESHEETPATH );
137 }
我想相关变量(?)是 TEMPLATEPATH。
我想使用样式表检查特定主题是否为子主题。
例如:
$childBoolean = functionHere( 'twentyfifteen' );
我需要某种功能来检查特定主题是否为子主题。它应该 return 一个布尔值。
那么,有没有一个函数可以检查它?有什么想法吗?
谢谢
您可以使用 is_child_theme()
检查当前主题是否是另一个主题的子主题。函数文档在这里:https://codex.wordpress.org/Function_Reference/is_child_theme
如果您知道如何使用此代码,它可能会有用:
1486 // Look in a parent theme first, that way child theme CSS overrides.
1487 if ( is_child_theme() ) {
1488 $template_uri = get_template_directory_uri();
1489 **$template_dir = get_template_directory();**
1490
1491 foreach ( $editor_styles as $key => $file ) {
1492 if ( $file && file_exists( "$template_dir/$file" ) ) {
1493 $stylesheets[] = "$template_uri/$file";
1494 }
1495 }
1496 }
(来自:wp-includes/theme.php,通过 AllysonSouza 评论中的 link。 我想您应该能够使用其中一些 php 命令或拉取变量来获取模板目录名称,这几乎总是主题名称。
$template_dir 或 get_template_directory();
此外,可能会使用以下内容:
128 /**
129 * Whether a child theme is in use.
130 *
131 * @since 3.0.0
132 *
133 * @return bool true if a child theme is in use, false otherwise.
134 **/
135 function is_child_theme() {
136 return ( **TEMPLATEPATH** !== STYLESHEETPATH );
137 }
我想相关变量(?)是 TEMPLATEPATH。