Link ACF in PHP template - Brown Surfing

Link ACF in PHP template

Posted on: July 5th, 2022
By: Efrain Lemus

Here’s the documentation directly from ACF itself: https://www.advancedcustomfields.com/resources/link/

$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>';
endif;

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.