WordPress 中的函数get_theme_support() 函数用于检索使用 add_theme_support() 声明的主题支持设置。get_theme_support() 检索有关通过 add_theme_support() 添加的主题支持功能的信息。

WordPress函数get_theme_support()获取注册支持时传递的主题参数

WordPress函数get_theme_support()获取注册支持时传递的主题参数

  WordPress 中的函数get_theme_support() 函数用于检索使用 add_theme_support() 声明的主题支持设置。get_theme_support() 检索有关通过 add_theme_support() 添加的主题支持功能的信息。对于在使用主题之前检查主题是否声明支持某个功能很有用。

  推荐:[最新版]Slider Revolution滑块插件WordPress滑块插件

get_theme_support()函数基本语法

描述

  注册给定功能的主题支持。

用法

get_theme_support('custom-logo');
get_theme_support('custom-header', 'width');

参数

  • $feature (string)– 必需的。要检查的功能。请参阅add_theme_support()参考资料 可能值的列表。
  • $args (mixed)– 选修的。根据某些功能检查额外的参数。

  推荐:[最新版]TranslatePress Pro插件下载WordPress翻译插件

get_theme_support()函数

  get_theme_support() 检索有关通过 add_theme_support() 添加的主题支持功能的信息。(源文件可参考这里

function get_theme_support( $feature, ...$args ) {
	global $_wp_theme_features;

	if ( ! isset( $_wp_theme_features[ $feature ] ) ) {
		return false;
	}

	if ( ! $args ) {
		return $_wp_theme_features[ $feature ];
	}

	switch ( $feature ) {
		case 'custom-logo':
		case 'custom-header':
		case 'custom-background':
			if ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) ) {
				return $_wp_theme_features[ $feature ][0][ $args[0] ];
			}
			return false;

		default:
			return $_wp_theme_features[ $feature ];
	}
}

  推荐:ProjectHuddle插件WordPress网站设计交流插件

如何使用get_theme_support()

  获取自定义徽标支持参数

// Get the custom logo theme support arguments
$custom_logo_support = get_theme_support('custom-logo');

// Output the custom logo support arguments
print_r($custom_logo_support);

  获取自定义标头支持参数

// Get the custom header theme support arguments
$custom_header_support = get_theme_support('custom-header');

// Output the custom header support arguments
print_r($custom_header_support);

  检查主题是否支持帖子缩略图

// Check if the theme supports post-thumbnails
if (current_theme_supports('post-thumbnails')) {
    echo "This theme supports post thumbnails.";
} else {
    echo "This theme does not support post thumbnails.";
}

  获取 HTML5 支持参数

// Get the HTML5 theme support arguments
$html5_support = get_theme_support('html5');

// Output the HTML5 support arguments
print_r($html5_support);

  检查主题是否支持响应式嵌入

// Check if the theme supports responsive-embeds
if (current_theme_supports('responsive-embeds')) {
    echo "This theme supports responsive embeds.";
} else {
    echo "This theme does not support responsive embeds.";
}

  推荐:WordPress函数wp_check_filetype()检索文件类型

  推荐:WordPress函数使用手册


滚动至顶部