woocommerce - Setting alt text of images automatically wordpress -
i have ecommerce site , want automate processes.firstly have begun images alt text.but have difficulties.i using wp user frontend plugin in order upload images , using "image upload" tag , not "featured image".post redirected pending.following code sets alt text automatically product thumbnail when publish it.but rest of images (image gallery), have update post second time.is possible set alt text gallery images automatically in first time because takes time set alt text 1 one manually.
code:
function set_alt_text_auto( $new_status, $old_status, $post) { $post = new wc_product(get_the_id()); $post_id = get_post_thumbnail_id( $post->id); //thumbnail of product $attachment_ids = $post->get_gallery_attachment_ids(); //rest of images if ( $new_status == 'publish' ) { //this thumbnail update_post_meta( $post_id, '_wp_attachment_image_alt','alt text' ); //this rest of images goes gallery of product foreach ($attachment_ids $att_id) { update_post_meta( $att_id, '_wp_attachment_image_alt','alt text' ); } } } add_action( 'transition_post_status', 'set_alt_text_auto',10,3);
Comments
Post a Comment