1. Có rất nhiều cách để tạo ra Child Theme trong WordPress 👌 Một trong những cách đơn giản nhất là:
  2. Tạo một thư mục mới có tên là 'child-theme-name' bên trong thư mục '/wp-content/themes/'.
  3. Tạo file 'style.css' bên trong thư mục child theme vừa tạo và thêm dòng sau đầu file:
  4. /*
  5. Theme Name: Child Theme Name
  6. Theme URI: https://www.example.com/theme/
  7. Description: Child theme of Parent Theme Name
  8. Author: Your Name
  9. Template: parent-theme-name
  10. Version: 1.0.0
  11. License: GNU General Public License v2 or later
  12. License URI: http://www.gnu.org/licenses/gpl-2.0.html
  13. Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
  14. Text Domain: child-theme-name
  15. */
  16. Tạo file 'functions.php' bên trong thư mục child theme và thêm dòng sau:
  17. <?php
  18. function my_theme_enqueue_styles() {
  19. $parent_style = 'parent-style';
  20. wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
  21. wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( $parent_style ) );
  22. }
  23. add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
  24. ?>
  25. Theme mới đã được tạo thành công. Bây giờ bạn có thể thêm CSS riêng 💪 vào file 'style.css' để thay đổi giao diện theo ý mình mà không ảnh hưởng đến theme gốc.
  26. Để cập nhật nội dung, bạn có thể sử dụng các filter và action hook của theme gốc 🤓.
  27. Đó là cách đơn giản nhất để tạo ra một Child Theme WordPress. Hy vọng bài viết giúp bạn nắm được cách thức hoạt động của Child Theme ✌️ và biết cách tùy chỉnh giao diện theo ý mình. Hãy luôn cập nhật kiến thức mới nhé! - hhuz5tyb99 - https://hostingraft.com/child-theme-wordpress-la-gi-cach-tao-nhu-the-nao/