Trường hợp lưu các tài nguyên trong theme wordpress các bạn muốn gọi ra thì phải dùng hàm lấy đường dẫn của theme hiện hành, theme con trên wordpress. Sử dụng 2 hàm sau để lấy ra đường dẫn tương ứng nhé!
- 1: Lấy đường dẫn theme cha của theme hiện hành
get_template_directory();
- 2: Lấy đường dẫn theme hiện tại, nếu đang xài theme con thì lấy đường dẫn theme con
get_stylesheet_directory();
Ví dụ cho 2 lệnh trên khi thêm vào code sẽ cho ra 2 kết quả như sau
function codfe_exam(){
echo get_template_directory().'</br>';
echo get_stylesheet_directory();
}
Kết quả:
1 …../wp-content/themes/flatsome : là đường dẫn theme cha
2 …/wp-content/themes/trungphong : là đường dẫn theme con đang sử dụng (trungphong là theme con của flatsome)
Trường hợp khai báo css hoặc js cho theme cần lấy url các bạn thêm _uri nữa nhé
function codfe_exam(){
echo get_template_directory_uri().'</br>';
echo get_stylesheet_directory_uri();
}
Bài viết mới:
- Cách để xóa thư mục Uncategorized trong wocommerce
- Thực thi & hiển thị shortcode trong mô tả danh mục (archive description), tag ….
- Kiểm tra và tự Khởi Động Lại MySQL Khi Quá Tải Trên Máy Chủ Linux, VPS, aaPanel
- Interesante plataforma para jugadores con thesolcasino-es.com y beneficios exclusivos
- Cách dùng Font Awesome bản miễn phí






