1. 首页
  2. WordPress 函数手册

current_theme_supports()

current_theme_supports( string $feature, mixed $args )

检查主题对给定功能的支持。
Checks a theme’s support for a given feature.

目录锚点:#说明#参数#返回#源码#笔记


说明(Description)

示例用法:

当前主题支持(“自定义徽标”);

当前主题支持(’html5’,’comment form’);


参数(Parameters)

参数 类型 必填 说明
$feature (string) 必需 正在检查的功能。
$args (mixed) 可选 要对照某些功能检查的额外参数。

返回(Return)

(bool)如果当前主题支持该功能,则为True,否则为false。


源码(Source)

/**
 * 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&#91;$feature&#93;="" )="" registered="" for="" all="" types="" return="" true;="" $content_type="$args&#91;0&#93;;" return="" in_array(="" $content_type,="" $_wp_theme_features&#91;$feature&#93;&#91;0&#93;="" );="" 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&#91;0&#93;;" return="" in_array(="" $type,="" $_wp_theme_features&#91;$feature&#93;&#91;0&#93;="" );="" 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&#91;0&#93;;" return="" (="" isset(="" $_wp_theme_features&#91;$feature&#93;&#91;0&#93;&#91;$header_support&#93;="" )="" &&="" $_wp_theme_features&#91;$feature&#93;&#91;0&#93;&#91;$header_support&#93;="" );="" }="" *="" *="" 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&#91;$feature&#93;="" );="" }="">
更新版本 源码位置 使用 被使用
5.3.0 wp-includes/theme.php:2826 72 3

笔记(Notes)

基本示例

current_theme_supports() 为WP2原创文章,链接:https://www.wp2.cn/functions/current_theme_supports/