Code tự động chèn thẻ alt và titlle lấy từ title của bài viết
Code tự động chèn thẻ alt và titlle lấy từ title của bài viết
add_filter('wp_get_attachment_image_attributes', 'change_attachement_image_attributes', 20, 2);
function change_attachement_image_attributes( $attr, $attachment ){
$parent = get_post_field( 'post_parent', $attachment);
$type = get_post_field( 'post_type', $parent);
if( $type != 'product' ){
return $attr;
}
$title = get_post_field( 'post_title', $parent);
$attr['alt'] = $title;
$attr['title'] = $title;
return $attr;
}Chúc bạn thành công
Nhận xét
Đăng nhận xét