Trong WordPress nói chung và theme Flatsome nói riêng, có cơ chế tạo folder child-theme
để chỉnh sửa được thuận tiện, không bị mất code khi update theme. Trong theme Flatsome chúng ta có thể ghi đè (override) được gần như toàn bộ các file, ngoại trừ chỉ có folder INC.
Để có thể ghi đè (override) inc trong theme Flatsome, các bạn áp dụng các bước sau, ở đây tôi sẽ ví dụ với file /inc/ux_products.php
:
Bài viết khác
- Kỹ năng tìm kiếm và giải quyết vấn đề trong lập trình
- Fix lỗi không khởi động được MySQL trên Xampp – MySQL shutdown unexpectedly
- Sàn Binance là gì ? Những điều cần biết về sàn giao dịch tiền điện tử Binance
- Cài đặt Google Search Console mới nhất cho website
- Hiển thị thêm thông tin từ ACF | Advanced Custom Fields trong WordPress
Bước 1. Sao chép file & folder
Sao chép /inc
từ theme Flatsome sang folder child-theme Flatsome (file nào cần thì sao chép, không thì copy tất cả cho nhanh)
Bước 2. Đổi tên function
Mở file /inc/shortcodes/ux_products.php
(hoặc file cần sửa trong child-theme) và đổi tên function
từ như này
function ux_products($atts, $content = null, $tag) {}
sang như này
function child_ux_products($atts, $content = null, $tag) {}
Bước 3. Đổi lại shortcode
Kéo xuống cuối file và chỉnh sửa từ như này
add_shortcode("ux_bestseller_products", "ux_products"); add_shortcode("ux_featured_products", "ux_products"); add_shortcode("ux_sale_products", "ux_products"); add_shortcode("ux_latest_products", "ux_products"); add_shortcode("ux_custom_products", "ux_products"); add_shortcode("product_lookbook", "ux_products"); add_shortcode("products_pinterest_style", "ux_products"); add_shortcode("ux_products", "ux_products");
sang như này
add_shortcode("ux_bestseller_products", "child_ux_products"); add_shortcode("ux_featured_products", "child_ux_products"); add_shortcode("ux_sale_products", "child_ux_products"); add_shortcode("ux_latest_products", "child_ux_products"); add_shortcode("ux_custom_products", "child_ux_products"); add_shortcode("product_lookbook", "child_ux_products"); add_shortcode("products_pinterest_style", "child_ux_products"); add_shortcode("ux_products", "child_ux_products");
Bước 4. Khai báo ghi đè đường dẫn file
Mở functions.php
trong child-theme và copy code sau
function vdh_override_shortcodes() { require get_stylesheet_directory() . '/inc/shortcodes/ux_products.php'; // Thêm file tương tự cần sửa vào đây } add_action('wp_loaded', 'vdh_override_shortcodes', 10);
Lưu ý rằng, khi theme cha được cập nhật, các thay đổi của trong child-theme
sẽ không bị mất. Tuy nhiên, nếu các thay đổi trong theme cha liên quan đến các file trong thư mục /inc, bạn có thể cần phải cập nhật lại các file tương ứng trong child-theme
của bạn để đảm bảo tính tương thích của theme và child-theme
.
Bài viết khác
- Hiển thị thêm thông tin từ ACF | Advanced Custom Fields trong WordPress
- Download video meme Facebook | Video comment Facebook thú vị, hài hước
- Plugin Progress Sold – Hiển thị số lượng “Đã bán” giống Shopee cho WooCommerce
- Plugin Active Flatsome All Version | Kích hoạt theme Flatsome
- Hướng dẫn cấu hình gửi Mail trong WordPress