Home › Forums › Pro Support › Link image in custom filed to the post url Tagged: alternate image, custom fields This topic has 3 replies, 2 voices, and was last updated 5 years ago by Tom. Viewing 4 posts - 1 through 4 (of 4 total) Author Posts November 19, 2018 at 2:42 am #6477 DanielParticipant Hi! I used this piece of code: add_action( 'wpsp_before_title', 'tu_add_custom_meta' ); function tu_add_custom_meta() { $image = get_post_meta( get_the_ID(), 'cami_thumb', true ); if ( isset( $image ) && '' !== $image ) { echo '<div class="imagen-producto"><img src="' . $image . '"></div>'; } } to display an image stored in a custom field. Now I would like to link it to the url of the post, how can I do it?? November 19, 2018 at 6:00 pm #6479 TomKeymaster Try this: add_action( 'wpsp_before_title', 'tu_add_custom_meta' ); function tu_add_custom_meta() { $image = get_post_meta( get_the_ID(), 'cami_thumb', true ); $permalink = get_permalink(); if ( isset( $image ) && '' !== $image ) { echo '<div class="imagen-producto"><a href="' . $permalink . '"><img src="' . $image . '"></a></div>'; } } November 20, 2018 at 5:04 am #6488 DanielParticipant Thanks Tom! Of course it works perfectly. November 20, 2018 at 5:22 pm #6495 TomKeymaster You’re welcome 🙂 Author Posts Viewing 4 posts - 1 through 4 (of 4 total) You must be logged in to reply to this topic. Log In Username: Password: Keep me signed in Log In