Black Friday sale! Get 25% off WPSP Pro! Discount automatically applied at checkout.

[Resolved] Link image in custom filed to the post url

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Link image in custom filed to the post url

  • This topic has 3 replies, 2 voices, and was last updated 2 years ago by Tom.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #6477
    Daniel
    Participant

    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??

    #6479
    Tom
    Keymaster

    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>';
        }
    }
    #6488
    Daniel
    Participant

    Thanks Tom!

    Of course it works perfectly.

    #6495
    Tom
    Keymaster

    You’re welcome 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.