Home › Forums › Front-end Issues › Link field not working
Hi,
Im using the following code to display a link in the template but it’s not working. Just returning ‘h’ for link and title, and nothing fro target.
Hi,
I’m using the following code to display a link in the template.
<?php
$link = get_field('custom_cta');
if( $link ):
$link_url = $link['url'];
$link_title = $link['title'];
$link_target = $link['target'] ? $link['target'] : '_self';
?>
<a class="button" href="<?php echo esc_url($link_url); ?>" target="<?php echo esc_attr($link_target); ?>"><?php echo esc_html($link_title); ?></a>
<?php endif; ?>
hahahaha… Still no answer huh?
I’m having the same problem and I can’t seem to find the answer.
Did you ever solved this?
OK, forget the “if” statement for now and don’t use the “esc_url”.
I’m using a repeater field and this worked for me:
<?php if( have_rows('lista_de_encuestas') ) : while ( have_rows('lista_de_encuestas') ) : the_row(); ?>
<?php
$pollUrls = get_sub_field('enlace_a_encuesta');
?>
<li>
<a href="<?php echo $pollUrls['url']; ?>"><?php echo $pollUrls['title']; ?></a>
</li>
<?php endwhile; endif; ?>
Not sure if the if statement has something to do with it. I tried the same thing over and over and for some reason when I deleted everything and did it over again it worked. I triple checked the code before and I don’t think I had any typos or errors but… who knows :/
Hope this helps
Hey guys.
I had the same issue and it seems that if you go to your Custom Forms and change the “Return Value” in your link field from “Link URL” to “Link Array” should do the trick.
Also, make sure that you change from this <?php echo esc_url($link_url); ?> to this <?php echo esc_url($link_url[‘url’]); ?>
The [‘url’] bit is important
Hi, I am hoping that this might work for me.
I want to use an URL from ACF to add a link to an icon in divi.
I have tried everything (i know), but am not a programmer so have not gone the PHP route.
What code can I use to add the URL to have this be the source?
<a href="websitelink" target="_blank" rel="noopener noreferrer">Image</a>
I would appreciate any advice you can give.
Thank you.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
ACF wouldn’t be so widely used in WordPress if it didn’t have some pretty amazing capabilities. In this article, we look at a few of the features we’ll discuss during “7 things you didn’t know you could do with ACF” at #WPEDecode later this month. https://t.co/5lnsTxp81j pic.twitter.com/Yf0ThPG1QG
— Advanced Custom Fields (@wp_acf) March 16, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.