Link ACF in PHP template

Posted on: July 5th, 2022
By: Tadeo Martinez

Here’s the documentation directly from ACF itself:

$link = get_field('link');
if( $link ): 
$link_url = $link['url'];
$link_title = $link['title'];
$link_target = $link['target'] ? $link['target'] : '_self';
echo '<a class="bg-accent btn" href="' . esc_url( $link_url ) . '" target="' . esc_attr( $link_target ) . '">' . esc_html( $link_title ) . '</a>';

If you’re using the link within a “group” or “repeater” then simply add “sub” between get and field

$link = get_sub_field('link');

Have any questions or comments? Write them below!

Leave a Reply

Your email address will not be published. Required fields are marked *