WordPress主题制作

  1. 主页
  2. 文档
  3. WordPress主题制作
  4. theme-setup
  5. theme setup内容说明(基于2020主题)

theme setup内容说明(基于2020主题)

1、添加默认文章和评论RSS feed链接

add_theme_support( ‘automatic-feed-links’ );

2、定制化背景颜色
add_theme_support(
‘custom-background’,
array(
‘default-color’ => ‘f5efe0’,
)
);
3、设置内容宽度

global $content_width;
if ( ! isset( $content_width ) ) {
$content_width = 580;
}

4、支持缩略图
add_theme_support( ‘post-thumbnails’ );

5、设置缩略图大小
set_post_thumbnail_size( 1200, 9999 );

6、添加用于封面的自定义图像大小
add_image_size( ‘twentytwenty-fullscreen’, 1980, 9999 );

7、关于logo
1)自定义logo
$logo_width = 120;
$logo_height = 90;

2)如果retina设置激活,双倍建议的宽度和高度
if ( get_theme_mod( ‘retina_logo’, false ) ) {
$logo_width = floor( $logo_width * 2 );
$logo_height = floor( $logo_height * 2 );
}

3)添加custom-logo
add_theme_support(
‘custom-logo’,
array(
‘height’ => $logo_height,
‘width’ => $logo_width,
‘flex-height’ => true,
‘flex-width’ => true,
)
);

8、使WordPress管理题目。添加后主题不适用在header.php中通过标签title实现:

[cc]add_theme_support( ‘title-tag’ );[/cc] 9、切换默认有关search form, comment form, and comments 核心markup 为输出合法的HTML5.

[cc]add_theme_support(
‘html5’,
array(
‘search-form’,
‘comment-form’,
‘comment-list’,
‘gallery’,
‘caption’,
‘script’,
‘style’,
)
);[/cc]

补充:
作用:为wordpress输出的html5文件是符合HTML5标准的;即主题支持HTML5。

10、针对翻译,对应目录/languages/ 。

[cc]load_theme_textdomain( ‘twentytwenty’ );[/cc]

11、支持全幅和宽对齐图像
[cc]add_theme_support( ‘align-wide’ );[/cc]

12、添加starter content以便highlight the theme on fresh sites.

* This is done conditionally to avoid loading the starter content on every
* page load, as it is a one-off operation only needed once in the customizer.
*/
if ( is_customize_preview() ) {
require get_template_directory() . ‘/inc/starter-content.php’;
add_theme_support( ‘starter-content’, twentytwenty_get_starter_content() );
}

13、添加selective refresh for widgets.
[cc]add_theme_support( ‘customize-selective-refresh-widgets’ );[/cc]

14、添加`async` and `defer` support for scripts registered or enqueued
* by the theme.
*/
[cc]$loader = new TwentyTwenty_Script_Loader();
add_filter( ‘script_loader_tag’, array( $loader, ‘filter_script_loader_tag’ ), 10, 2 );[/cc]


参考:
https://blog.wpjam.com/function_reference/add_theme_support/

这篇文章对您有用吗?

我们要如何帮助您?