0

Good afternoon everyone, I have little experience in php programming and I have a problem with the featured images. Use Advanced Custom Field’s and create a field where i put a URL. Need when click in the featured image this take the URL of ACF and open in new tab. I found this code where the featured image call the link, but i need to put my custom URL.

    if ( $args['apply_link'] ) {
    $out_escaped .= '<a class="g1-frame" href="' . esc_url( apply_filters( 'the_permalink', get_permalink( $post ), $post ) ) . '">';
    $out_escaped .= '<span class="g1-frame-inner"' . $inner_style_escaped . '>';

    if ( $args['use_microdata'] ) {
        $out_escaped .= get_the_post_thumbnail( null, $args['size'], array( 'itemprop' => 'contentUrl' ) );
    } else {
        $out_escaped .= get_the_post_thumbnail( null, $args['size'] );
    }

    $out_escaped .= '<span class="g1-frame-icon"></span>';

I dont know how to call my custom URL to add in featured image. The code of ACF is ?php the_field('custom_url'); ?>

Some idea to work properly?

thank you very much in advance.

0

you can do this pretty simply. I'm guessing you are inside the wordpress loop. Basically, get the link url, get the image url, echo out.

<?php 
  $custom_link = the_field('custom_url'); //probably want to check if this is empty
  $post_thumb = get_the_post_thumbnail( $post_id );//you can pass size if you would like
  echo '<a href="' . $custom_link . ' target="_blank"><img src="' . $post_thumb . '/></a>';
?>

https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.