Chuyển đến nội dung chính

Add theme support trong wordpress

Add theme support trong wordpress - Add theme support trong wordpress

Source: Add theme support trong wordpress

Vậy làm thế nào để thêm hỗ trợ theme trong wordpress và áp dụng nó như thế nào?

Trong quá trình thiết kế theme wordpress, phần header (logo và banner background) và background của toàn bộ trang (hình ảnh và màu nền) hai thành phần này chúng ta có thể cho người dùng theme tự do lựa chọn.

Dem so luot xem bai viet WordPress - Add theme support trong wordpress

Add theme support trong wordpress - Add theme support trong wordpress

Add_theme_support () là hàm khai báo tính năng mà theme đó hỗ trợ. Nó được khai báo trong tệp functions.php của chủ đề. Nó có thể được khai báo bên ngoài hoặc gắn vào hook after_setup_theme. Trong bài viết này, mình sẽ chia sẻ một số khai báo tính năng hỗ trợ cho các theme sử dụng hàm add_theme_support ().

Cú pháp hàm add_theme_support ()

Cú pháp: 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' );

Giới thiệu một số tính năng cơ bản:

1: Chủ đề hỗ trợ Đăng hình thu nhỏ
1640433028 179 Add theme support trong wordpress - Add theme support trong wordpress

add_theme_support( 'post-thumbnails' );

2: Chủ đề hỗ trợ thay đổi logo

1640433028 563 Add theme support trong wordpress - Add theme support trong wordpress

add_theme_support (
‘biểu tượng tùy chỉnh’,
mảng(
‘height’ => $ logo_height,
‘width’ => $ logo_width,
‘flex-height’ => true,
‘flex-width’ => true,
)
);
3: Tùy chỉnh nền:
 $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: Hỗ trợ HTML 5
add_theme_support( 'html5', array( 'comment-list', 'comment-form', 'search-form', 'gallery', 'caption' ) );
5: Định dạng bài viết:
$post_formats = array('aside','image','gallery','video','audio','link','quote','status');
    add_theme_support( 'post-formats', $post_formats);

Phần kết

Như vậy là mình đã giúp các bạn hiểu thêm về chức năng hỗ trợ thêm theme trong wordpress rất đơn giản và dễ hiểu.

Nếu thấy hay các bạn có thể theo dõi chuyên mục thủ thuật wordpress để biết thêm nhiều kiến ​​thức mới nhé.

Theo dõi fanpage để nhận những bài viết mới nhất: Hocwordpress Group

Chúc các bạn có những kiến ​​thức bổ ích và thú vị về wordpress!

Via: sieucoder.com



from sieucoder.com https://ift.tt/3EsNFLO
via Sieucoder.com

Nhận xét