Support

Account

Home Forums Front-end Issues Link field not working

Solving

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; ?>
    • MrHOGDOG

    • December 25, 2019 at 10:49 am

    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?

    • MrHOGDOG

    • December 25, 2019 at 11:13 am

    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

    • deni

    • May 21, 2020 at 4:02 am

    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.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

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.