最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Add custom url to featured image

programmeradmin0浏览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.

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.

Share Improve this question asked Dec 16, 2016 at 18:12 El PelusaEl Pelusa 112 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

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/reference/functions/get_the_post_thumbnail/

发布评论

评论列表(0)

  1. 暂无评论