Site logo

Archived topic

Images Alt text

10 replies · Started by ustar on March 11, 2020

Viewing posts 1–11 of 11

Hi, there!

I noticed that Alt texts and Titles for image gallery is not showing in the code of page.
For example, i see only alt text and title in preview images when i browse on mobile screen.
When i see page on desktop, no alt text in code.
But, i checked all images for this product and all images witn metadata.

Could you please help me to fix this?
Thanks in advance.

Regards, Sergey.

Hi there,

it looks like you used Niche from the GP Site library to create the Gallery Stack.
If so you would need to update the Appearance > Elements .... the Hook Element named Gallery Stack

let us know if thats the case.

Hi, David!

Shold i just push button "Update" or i need to replace the code?
If i need use the new code, where i can find it?

Regards, Sergey.

Its going to require some new code - Title attribute is fairly simple but the getting the Alt is proving to be a pain. Can you paste the code you have in your current Gallery Stack Hook here so i can take a look at the changes it will require.

When adding code to the forum can you highlight the code and click the Code Button before submitting.

Hi, David!

The code is original. I have changed nothing.

<div class="woo-sumamry-wrap"><!-- open wrap -->
	<div class="woo-gallery-stack hide-on-mobile">
		<?php 
		global $product;
		
		if ( has_post_thumbnail( $product->get_id() ) ) {
    	$attachment_ids[0] = get_post_thumbnail_id( $product->get_id() );
    	$attachment = wp_get_attachment_image_src( $attachment_ids[0], 'full' ); 
			?>    
    	<img src="<?php echo $attachment[0] ; ?>"/>
			<?php 
		}

		if ( method_exists( $product, 'get_gallery_image_ids' ) ) {
			$product_image_ids = $product->get_gallery_image_ids();

			foreach( $product_image_ids as $product_image_id ) {
				$image_url = wp_get_attachment_url( $product_image_id, 'full' );
				echo '<img src="' . $image_url . '">';
			}
		}
	// Closing div found in Close Summary Wrap element
	?>
</div>

Following this thread also...

Try this instead:

<div class="woo-sumamry-wrap"><!-- open wrap -->
	<div class="woo-gallery-stack hide-on-mobile">
		<?php 
		    global $product;

            // Get post product thumbnail
		    if ( has_post_thumbnail( $product->get_id() ) ) {
    	        $attachment_ids[0] = get_post_thumbnail_id( $product->get_id() );
                $attachment = wp_get_attachment_image_src( $attachment_ids[0], 'full' ); 
                $attachment_alt = get_post_meta( $attachment_ids[0], '_wp_attachment_image_alt', TRUE);
                $attachmnent_title = get_the_title( $attachment_ids[0] );
		    ?>    
    	        <img src="<?php echo $attachment[0] ; ?>" alt="<?php echo $attachment_alt; ?>" title="<?php echo $attachmnent_title; ?>" />
		    <?php 
		    }

            // Get Product Gallery Images
		    if ( method_exists( $product, 'get_gallery_image_ids' ) ) {
			    $product_image_ids = $product->get_gallery_image_ids();

			    foreach( $product_image_ids as $product_image_id ) {
                    $image_url = wp_get_attachment_url( $product_image_id, 'full' );
                    $image_alt = get_post_meta( $product_image_id, '_wp_attachment_image_alt', TRUE);
                    $image_title = get_the_title( $product_image_id );
                    echo '<img src="' . $image_url . '" alt="' . $image_alt . '" title="' . $image_title . '">';
			    }
		    }
	    // Closing div found in Close Summary Wrap element
	    ?>
</div>

Hi, David!

Alt texts on the code now! Thank you very much!

Regards, Sergey.

)

Thank you @ustar for the thread, thank you @David for the solution!

Awesome - ill update Niche when i get a moment.

This archived topic is closed to new replies.