WordPress函数current_theme_supports()

描述:

判断当前主题是否支持某个功能特性

用法:

<?php current_theme_supports( $feature ); ?>

参数:

$feature

(string) (必填) 要查询的特色功能

默认值: None

特色功能列表:

  • ‘post-thumbnails’
  • ‘post-formats’
  • ‘custom-header’
  • ‘custom-background’
  • ‘menus’
  • ‘automatic-feed-links’
  • ‘editor-style’
  • ‘widgets’
  • ‘html5’
  • ‘title-tag’

源文件:

/**
 * Checks a theme's support for a given feature
 *
 * @since 2.9.0
 *
 * @global array $_wp_theme_features
 *
 * @param string $feature the feature being checked
 * @return bool
 */
function current_theme_supports( $feature ) {
	global $_wp_theme_features;

	if ( 'custom-header-uploads' == $feature )
		return current_theme_supports( 'custom-header', 'uploads' );

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

	if ( 'title-tag' == $feature ) {
		// Don't confirm support unless called internally.
		$trace = debug_backtrace();
		if ( ! in_array( $trace[1]['function'], array( '_wp_render_title_tag', 'wp_title' ) ) ) {
			return false;
		}
	}

	// If no args passed then no extra checks need be performed
	if ( func_num_args() <= 1="" )="" return="" true;="" $args="array_slice(" func_get_args(),="" 1="" );="" switch="" (="" $feature="" )="" {="" case="" 'post-thumbnails':="" post-thumbnails="" can="" be="" registered="" for="" only="" certain="" content/post="" types="" by="" passing="" an="" array="" of="" types="" to="" add_theme_support().="" if="" no="" array="" was="" passed,="" then="" any="" type="" is="" accepted="" if="" (="" true="==" $_wp_theme_features[$feature]="" )="" registered="" for="" all="" types="" return="" true;="" $content_type="$args[0];" return="" in_array(="" $content_type,="" $_wp_theme_features[$feature][0]="" );="" case="" 'html5':="" case="" 'post-formats':="" specific="" post="" formats="" can="" be="" registered="" by="" passing="" an="" array="" of="" types="" to="" add_theme_support()="" specific="" areas="" of="" html5="" support="" *must*="" be="" passed="" via="" an="" array="" to="" add_theme_support()="" $type="$args[0];" return="" in_array(="" $type,="" $_wp_theme_features[$feature][0]="" );="" case="" 'custom-header':="" case="" 'custom-background'="" :="" specific="" custom="" header="" and="" background="" capabilities="" can="" be="" registered="" by="" passing="" an="" array="" to="" add_theme_support()="" $header_support="$args[0];" return="" (="" isset(="" $_wp_theme_features[$feature][0][$header_support]="" )="" &&="" $_wp_theme_features[$feature][0][$header_support]="" );="" }="" *="" *="" filter="" whether="" the="" current="" theme="" supports="" a="" specific="" feature.="" *="" *="" the="" dynamic="" portion="" of="" the="" hook="" name,="" `$feature`,="" refers="" to="" the="" specific="" theme="" *="" feature.="" possible="" values="" include="" 'post-formats',="" 'post-thumbnails',="" 'custom-background',="" *="" 'custom-header',="" 'menus',="" 'automatic-feed-links',="" and="" 'html5'.="" *="" *="" @since="" 3.4.0="" *="" *="" @param="" bool="" true="" whether="" the="" current="" theme="" supports="" the="" given="" feature.="" default="" true.="" *="" @param="" array="" $args="" array="" of="" arguments="" for="" the="" feature.="" *="" @param="" string="" $feature="" the="" theme="" feature.="" */="" return="" apply_filters(="" "current_theme_supports-{$feature}",="" true,="" $args,="" $_wp_theme_features[$feature]="" );="" }="">