K
K
Konstantin Timosheno2018-04-15 11:56:42
WordPress
Konstantin Timosheno, 2018-04-15 11:56:42

Display product image as url (link to file)?

Hello. There was a need to display the product thumbnail exactly as the address to the file. Now the output goes like this

if ( has_post_thumbnail() ) { 			
      $html  = wc_get_gallery_image_html( $post_thumbnail_id, true );
    }

and the output is like this
<div data-thumb="http://franch.local/wp-content/uploads/2018/03/maxresdefault-100x100.jpg" class="woocommerce-product-gallery__image"><a href="http://franch.local/wp-content/uploads/2018/03/maxresdefault.jpg"><img src="http://franch.local/wp-content/uploads/2018/03/maxresdefault-600x338.jpg" class="wp-post-image" alt="" title="maxresdefault" data-caption="" data-src="http://franch.local/wp-content/uploads/2018/03/maxresdefault.jpg" data-large_image="http://franch.local/wp-content/uploads/2018/03/maxresdefault.jpg" data-large_image_width="" data-large_image_height=""></a></div>

Is it possible to display exactly the address of the image? For example like this
http://franch.local/wp-content/uploads/2018/03/maxresdefault-600x338.jpg

Thank you in advance for your response.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2018-04-17
@kastembay

1. Display the image immediately as HTML - https://developer.wordpress.org/reference/function...

if ( has_post_thumbnail() ) {
    the_post_thumbnail();
}

2. Output only its url (in your markup) - https://developer.wordpress.org/reference/function...
<?php if ( has_post_thumbnail() ) : ?>
   <img src="<?php the_post_thumbnail_url(); ?>" alt="">
<?php endif; ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question