WordPress函数:add_theme_support 为主题添加功能特性

追格官方小助手/ 2023年01月12日/ WordPress/ 浏览 1747

在开发 WordPress 主题时,add_theme_support 函数非常有用。


add_theme_support 就像一把钥匙,可以打开各种 WordPress 的功能。


一般的,只需要在 functions.php 中使用 add_theme_support 函数就可以了。如果是使用钩子的话,务必使用 after_setup_theme 钩子;在 init 钩子中执行相关代码的话,就太迟了。


使用举例:


add_theme_support( 'title-tag' );

add_theme_support( 'custom-logo', array(
    'height' => 480,
    'width'  => 720,
) );

add_theme_support( 'post-thumbnails' );

add_theme_support( 'automatic-feed-links' );

add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );

add_theme_support(
    'custom-background',
    array(
        'default-color' => '0B3B41',
        'default-image' => get_template_directory_uri().'/images/bg.jpg',
    )
);

add_theme_support( 'custom-header' );


支持的特性总结如下:

'admin-bar'

'align-wide'

'automatic-feed-links'

'core-block-patterns'

'custom-background'

'custom-header'

'custom-line-height'

'custom-logo'

'customize-selective-refresh-widgets'

'custom-spacing'

'custom-units'

'dark-editor-style'

'disable-custom-colors'

'disable-custom-font-sizes'

'editor-color-palette'

'editor-gradient-presets'

'editor-font-sizes'

'editor-styles'

'featured-content'

'html5'

'menus'

'post-formats'

'post-thumbnails'

'responsive-embeds'

'starter-content'

'title-tag'

'wp-block-styles'

'widgets'

'widgets-block-editor'


发表评论

暂无评论,抢个沙发...

客服 工单