最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugin development - Will current_theme_supports return TRUE with a nonstandard add_theme_support?

programmeradmin2浏览0评论

Will current_theme_supports() return TRUE with a nonstandard add_theme_support() string?

If I do this in my theme:

add_theme_support( 'my_funky_new_thing' );

Can someone else writing a plugin do this?

if( current_theme_supports( 'my_funky_new_thing' ) ){
    // ...
}

Will current_theme_supports() return TRUE with a nonstandard add_theme_support() string?

If I do this in my theme:

add_theme_support( 'my_funky_new_thing' );

Can someone else writing a plugin do this?

if( current_theme_supports( 'my_funky_new_thing' ) ){
    // ...
}
Share Improve this question edited Jun 28, 2019 at 19:14 Matthew Brown aka Lord Matt asked Jun 27, 2019 at 23:00 Matthew Brown aka Lord MattMatthew Brown aka Lord Matt 1,0683 gold badges13 silver badges34 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 2

Yes. You can take advantage of this to enable or disable features in your plugin if a theme does or does not declare support for a feature. WooCommmerce is an example of a plugin that does this.

As a side note for those interested, you can also pass parameters with your custom theme support.

// theme functions.php
add_theme_support( 'some_feature', array(
  'arg_foo',
  'arg_bar'
) );

// plugin.php
$feature_args = get_theme_support( 'some_feature' );
var_dump( $feature_args );
// array(
//   array(
//     'arg_foo',
//     'arg_bar'
//   )
// );
发布评论

评论列表(0)

  1. 暂无评论