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.
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
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.
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!
© 2020 Advanced Custom Fields. Subscribe