Add theme support in wordpress – Learn WordPress from a to z

Tutorials 0 lượt xem

So how to add theme support in wordpress and how to apply it?

In the process of designing a wordpress theme, the header (logo and background banner) and the background of the whole page (image and color background) these two components we can give the theme user the freedom to choose.

Add_theme_support() is a function to declare the feature that the theme supports. It is declared in the theme’s functions.php file. It can be declared externally or attached to the  after_setup_theme hook . In this article, I will share some support feature declarations for themes using the add_theme_support() function.

Add_theme_support() function syntax

Syntax:  add_theme_support ( chuỗi tính năng );

function theme_setup() {
   add_theme_support( 'Tính năng 1' );
   add_theme_support( 'Tính năng 2' );
   add_theme_support( 'Tính năng n' );
}
add_action( 'after_setup_theme', 'theme_setup' );
<div>
<span>1</span><span>2</span><span>3</span><span>4</span><span>5</span><span>6</span>
</div>

Introducing some basic features:

1: Theme supports Post Thumbnails

add_theme_support(  'post-thumbnails'  );

2: Theme supports logo change


add_theme_support(
        ‘custom-logo’,
        array(
            ‘height’ => $logo_height,
            ‘width’ => $logo_width,
            ‘flex-height’ => true,
            ‘flex-width’ => true,
        )
    );
3: Customize background:
  $bg_defaults = array (
         'default-image'           => '' ,
         'default-preset'          => 'default' ,
         'default-size'            => 'cover' ,
         'default-repeat'          => 'no-repeat' ,
         'default-attachment'      => 'scroll' ,
     );
     add_theme_support( 'custom-background' , $bg_defaults );
4: HTML 5 Support
add_theme_support( 'html5' , array ( 'comment-list' , 'comment-form' , 'search-form' , 'gallery' , 'caption' ) );
5: Post format:
$post_formats = array ( 'aside' , 'image' , 'gallery' , 'video' , 'audio' , 'link' , ] , 'status' );
     add_theme_support( 'post-formats' , $post_formats );

Epilogue

So I have helped you understand more about the add support theme function in wordpress very simple and easy to understand.

If you find it interesting, you can follow the  wordpress tips section  to know more new knowledge.

Follow fanpage to receive the latest posts:  Group

Wish you have interesting and interesting knowledge about wordpress!

Bài viết liên quan