Created
May 15, 2023 19:34
-
-
Save aslamatwebdevstudios/1b3beb0120fcf76ad1455000d275b09a to your computer and use it in GitHub Desktop.
Get link html generated using acf link field
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 | |
if ( ! function_exists( 'wds_get_acf_link_html' ) ) { | |
/** | |
* Get link html generated using acf link field | |
* | |
* @return string | |
*/ | |
function wds_get_acf_link_html( $link, $other_attr = array(), $icon = '' ) { | |
$other_attr_html = ''; | |
if ( $other_attr ) { | |
foreach ( $other_attr as $key => $value ) { | |
$other_attr_html .= ' ' . $key . '="' . $value . '"'; | |
} | |
} | |
$link_html = '<a href="' . esc_url( $link['url'] ) . '" target="' . esc_attr( $link['target'] ) . '" ' . $other_attr_html . '>' . esc_html( $link['title'] ) . $icon . '</a> '; | |
return $link_html; | |
} | |
} | |
// Usage: | |
echo wds_get_acf_link_html( 'my_link_field_name', [ "class" => "button" ], '<i class="fa fa-user"></i>' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment