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

追格官方小助手/ 01月12日/ WordPress/ 浏览 203

在开发 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' );


发表评论

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

客服 工单