Image link in Functions
-
Good day,
I’m using the below code for display custom image (cmb2 plugin) in my theme. Everything work fine. If I using the below code I just got image < img src=”” > but I need image link, so if my site visitor click the image, the full image will display.
function cmb2_output_file_list( $file_list_meta_key, $img_size = 'medium' ) { // Get the list of files $files = get_post_meta( get_the_ID(), $file_list_meta_key, 1 ); echo '<div class="img_post">'; // Loop through them and output an image foreach ( (array) $files as $attachment_id => $attachment_url ) { echo '<div class="img_post_items">'; echo wp_get_attachment_image( $attachment_id, $img_size ); echo '</div>'; } echo '</div>'; }
The output:
<div class="img_post"> <div class="img_post_items"> <img width="500" height="200" alt="name" class="attachment-full" src="https://domain.com/wp-content/uploads/2016/02/Best.jpg"> </div> </div>
My question is: How to get the full image url to link the image?
Like this:
<div class="img_post"> <div class="img_post_items"> <a href="https://domain.com/wp-content/uploads/2016/02/Best.jpg"><img width="500" height="200" alt="name" class="attachment-full" src="https://domain.com/wp-content/uploads/2016/02/Best.jpg"></a> </div> </div>
Can someone help me, please!
Many thanks.
Shine
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Image link in Functions’ is closed to new replies.