current_theme_supports()

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

用法

<?php current_theme_supports( $feature ); ?>

参数

$feature

(string) (必填) the feature being checked

默认值: None

Features list:

‘post-thumbnails’

‘post-formats’

‘custom-header’

‘custom-background’

‘menus’

‘automatic-feed-links’

‘editor-style’

‘widgets’

‘html5’

‘title-tag’

返回值

(boolean) 

示例

/* ———————————-
* 星空站长网收集整理 
* ———————————- */
<?php

if (current_theme_supports(‘custom-header’)) {

  // do something special when custom-header is supported…

}
?>

注意

使用到 global: (unknown type) $_wp_theme_features

历史

添加于 版本: 2.9.0

源文件

current_theme_supports() 函数的代码位于 wp-includes/theme.php.

/* ———————————-
* wordpress函数 WWW.XINGKONGWEB.COM收集
* ———————————- */
/**
* 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]=“” );=“” }=“”></=>

相关

Theme Support:
add_theme_support(),
remove_theme_support(),
current_theme_supports()

Theme Features:
sidebar,
menus,
post-formats,
title-tag,
custom-background,
custom-header,
post-thumbnails,
automatic-feed-links,
html5,
editor-style,
content_width

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索