Created
January 9, 2024 16:30
-
-
Save colorful-tones/12eab97812421422959d08d443bef303 to your computer and use it in GitHub Desktop.
Parsing an ACF Link field type with defaults
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$my_link = get_field( 'my_link' ); | |
if ( $my_link ) { | |
$link_url = ! empty( $my_link['url'] ) ? $my_link['url'] : 'https://google.com'; | |
$link_title = ! empty( $my_link['title'] ) ? $my_link['title'] : 'Your quote here...'; | |
$link_target = $my_link['target'] ? $my_link['target'] : '_self'; | |
} | |
?> | |
<a href="<?php echo esc_url( $link_url ); ?>" target="<?php echo esc_attr( $link_target ); ?>"><?php echo esc_html( $link_title ); ?></a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment