获得附件ID后,可以通过设置_wp_attachment_image_alt
附件的post meta:
update_post_meta( $attachment_id, \'_wp_attachment_image_alt\', \'Alt text here\' );
获取附件ID的步骤
media_sideload_image()
您可以将第四个参数设置为
\'id\'
:
$attachment_id = media_sideload_image( $file, $post_id, $desc, \'id\' );
if ( ! is_wp_error( $attachment_id ) ) {
update_post_meta( $attachment_id, \'_wp_attachment_image_alt\', \'Alt text here\' );
}