Đầu tiền chỉ cần copy code sau và thêm vào file functions.php của child theme bạn đang xài là được.
|
function replace_product_cat_desc_editor( $term ) {
?>
<script>
jQuery(document).ready(function($) {
$(‘#tag-description’).closest(‘.form-field’).hide();
});
</script>
<?php
// Lấy nội dung mô tả hiện tại
$description = ( isset( $term->description ) ) ? $term->description : ”;
?>
<tr class=“form-field term-description-wrap”>
<th scope=“row”><label for=“description”>Mô tả</label></th>
<td>
<?php
// Hiển thị trình soạn thảo WYSIWYG
wp_editor( htmlspecialchars_decode( $description ), ‘tag_description’, array(
‘textarea_name’ => ‘description’,
‘media_buttons’ => true,
‘textarea_rows’ => 10,
‘teeny’ => false,
‘quicktags’ => true,
‘editor_class’ => ‘full-text-editor’,
) );
?>
<p class=“description”>Phần mô tả chi tiết hiển thị trên trang danh mục sản phẩm.</p>
</td>
</tr>
<?php
}
// Dùng cho trang chỉnh sửa chuyên mục sản phẩm
add_action( ‘product_cat_edit_form_fields’, ‘replace_product_cat_desc_editor’, 10, 1 );
remove_filter( ‘pre_term_description’, ‘wp_filter_kses’ );
remove_filter( ‘term_description’, ‘wp_kses_data’ );
function save_product_cat_desc_editor( $term_id ) {
if ( isset( $_POST[‘description’] ) ) {
$data = array(
‘description’ => wp_kses_post( $_POST[‘description’] )
);
wp_update_term( $term_id, ‘product_cat’, $data );
}
}
add_action( ‘edited_product_cat’, ‘save_product_cat_desc_editor’ );
add_action( ‘create_product_cat’, ‘save_product_cat_desc_editor’ );
|
Sau khi thêm vào là xong nhé, bình thường nội dung mô tả danh mục sản phẩm sẽ nằm bên trên danh sách sản phẩm trong trang danh mục nhé.
Code thêm tool vào danh mục bài viết
Copy code sau và thêm vào file functions.php.
|
// Bật WYSIWYG editor cho mô tả danh mục bài viết (Category)
function category_desc_wysiwyg_editor( $term ) {
?>
<script>
jQuery(document).ready(function($) {
$(‘#tag-description’).closest(‘.form-field’).hide();
});
</script>
<?php
$description = isset( $term->description ) ? $term->description : ”;
?>
<tr class=“form-field term-description-wrap”>
<th scope=“row”><label for=“description”>Mô tả</label></th>
<td>
<?php
wp_editor( htmlspecialchars_decode( $description ), ‘tag_description’, array(
‘textarea_name’ => ‘description’,
‘media_buttons’ => true,
‘textarea_rows’ => 10,
‘teeny’ => false,
‘quicktags’ => true,
) );
?>
<p class=“description”>Mô tả hiển thị trên trang danh mục bài viết.</p>
</td>
</tr>
<?php
}
add_action( ‘category_edit_form_fields’, ‘category_desc_wysiwyg_editor’, 10, 1 );
// Cho phép HTML trong mô tả danh mục
remove_filter( ‘pre_term_description’, ‘wp_filter_kses’ );
remove_filter( ‘term_description’, ‘wp_kses_data’ );
// Lưu nội dung editor
function save_category_desc_wysiwyg_editor( $term_id ) {
if ( isset( $_POST[‘description’] ) ) {
wp_update_term( $term_id, ‘category’, array(
‘description’ => wp_kses_post( $_POST[‘description’] )
) );
}
}
add_action( ‘edited_category’, ‘save_category_desc_wysiwyg_editor’ );
add_action( ‘create_category’, ‘save_category_desc_wysiwyg_editor’ );
|
