更新日期:2014-09-13
這一篇主要介紹 add_theme_support() 讓你的佈景主題增加一些功能,通常需放在 after_setup_theme() 中就要呼叫使用。
function sig_theme_setup() { // 使用文章格式. add_theme_support( 'post-formats', array( 'aside', 'image', 'link', 'quote', 'status' ) ); // 使用特色圖片 add_theme_support( 'post-thumbnails' ); // 自定背景顏色 add_theme_support( 'custom-background', array('default-color' => 'e6e6e6') ); // 自定表頭圖 add_theme_support( 'custom-header' ); // 加入 RSS feed links add_theme_support( 'automatic-feed-links' ); // 在評論表格、搜尋表格或評論清單等等地方使用 HTML5 標記。 add_theme_support( 'html5', array( 'comment-list', 'comment-form', 'search-form', 'gallery', 'caption' ) ); } add_action( 'after_setup_theme', 'sig_theme_setup' );
相關功能補充說明:
1.post-thumbnails
add_theme_support( 'post-thumbnails', array( 'post' ) ); // Posts only add_theme_support( 'post-thumbnails', array( 'page' ) ); // Pages only add_theme_support( 'post-thumbnails', array( 'post', 'movie' ) ); // Posts and Movies
2.custom-background (版本3.4之後才支援)
$defaults = array( 'default-color' => '', 'default-image' => '', 'wp-head-callback' => '_custom_background_cb', 'admin-head-callback' => '', 'admin-preview-callback' => '' ); add_theme_support( 'custom-background', $defaults );
3.custom-header (版本3.4之後才支援)
$defaults = array( 'default-image' => '', 'random-default' => false, 'width' => 0, 'height' => 0, 'flex-height' => false, 'flex-width' => false, 'default-text-color' => '', 'header-text' => true, 'uploads' => true, 'wp-head-callback' => '', 'admin-head-callback' => '', 'admin-preview-callback' => '', ); add_theme_support( 'custom-header', $defaults );
4.html5 (版本3.6之後才支援)