17

Chèn khung soạn thảo danh mục sản phẩm Flatsome

Trong bài viết này, mình sẽ hướng dẫn bạn cách sử dụng đoạn mã PHP tùy chỉnh để thay thế…

Trong bài viết này, mình sẽ hướng dẫn bạn cách sử dụng đoạn mã PHP tùy chỉnh để thay thế trình soạn thảo mặc định bằng trình soạn thảo WP Editor (trình soạn thảo giống như trong bài viết WordPress), giúp bạn dễ dàng tạo nội dung đa dạng và chuyên nghiệp hơn. Bài viết được thiết kế chi tiết, dễ hiểu cho cả người mới bắt đầu và những nhà phát triển có kinh nghiệm.

Hiện tại (mặc định flatsome), khi tối ưu onpage cho danh mục (viết content SEO cho danh mục – category onpage) thì sẽ không có khung editor để soạn thảo văn bản mà a/e thường phải viết ở trình soạn thảo html ở nơi khác rồi add vào (ví dụ: notepad++, html editor,…).

Để giải quyết vấn đề như ảnh dưới, thì a/e add code vào file function.php để hiển thị khung editor.

Hướng Dẫn Cài Đặt Và Sử Dụng Đoạn Mã

Bước 1: Thêm Đoạn Mã Vào File functions.php

Để edit file function.php thì bạn có thể vào source qua ssh or cài đặt plugin: file manager để view code file function.php trong flatsome child như hình dưới:

Thêm code dưới vào file function.php

code trong file này: https://anotepad.com/notes/wq5m852i hoặc coppy trực tiếp bên dưới

add_action('init', function () {
remove_action('product_cat_edit_form_fields', 'top_text_taxonomy_edit_meta_field', 10);
remove_action('product_tag_edit_form_fields', 'top_text_taxonomy_edit_meta_field', 10);
remove_action('product_cat_edit_form_fields', 'bottom_text_taxonomy_edit_meta_field', 10);
remove_action('product_tag_edit_form_fields', 'bottom_text_taxonomy_edit_meta_field', 10);

add_action('product_cat_edit_form_fields', 'nguyenlan_editor_top', 10, 2);
add_action('product_tag_edit_form_fields', 'nguyenlan_editor_top', 10, 2);
add_action('product_cat_edit_form_fields', 'nguyenlan_editor_bottom', 10, 2);
add_action('product_tag_edit_form_fields', 'nguyenlan_editor_bottom', 10, 2);
});

function nguyenlan_editor_top($term) {
$meta = get_term_meta($term->term_id, 'cat_meta', true);
$content = isset($meta['cat_header']) ? $meta['cat_header'] : '';
echo '<tr class="form-field"><th><label for="term_meta[cat_header]">Top Content</label></th><td>';
wp_editor($content, 'term_meta_cat_header', ['textarea_name' => 'term_meta[cat_header]', 'media_buttons' => true, 'textarea_rows' => 10]);
echo '</td></tr>';
}

function nguyenlan_editor_bottom($term) {
$meta = get_term_meta($term->term_id, 'cat_meta', true);
$content = isset($meta['cat_footer']) ? $meta['cat_footer'] : '';
echo '<tr class="form-field"><th><label for="term_meta[cat_footer]">Bottom Content</label></th><td>';
wp_editor($content, 'term_meta_cat_footer', ['textarea_name' => 'term_meta[cat_footer]', 'media_buttons' => true, 'textarea_rows' => 10]);
echo '</td></tr>';
}

Bước 2: Kiểm tra trình soạn thảo mới trong category

Như vậy a/e đã có khung editor để tiện lợi trong quá trình tối ưu onpage SEO cho danh mục rồi nhé.

Nguồn: nguyenlan blog

danghoa

Leave a Reply

Your email address will not be published. Required fields are marked *