Hello,
I’m creating button using acf link field and showing that with shortcode on my website.
I use this for products description and I want to show message to the user if link filed is empty, something like “No available downloads for this product”.
This is my code:
function notna_slika_link() {
$link = get_field('prikaz_notne_slike');
if( $link );
$link_url = $link['url'];
$link_title = $link['title'];
$link_target = $link['target'] ? $link['target'] : '_self';
return
'<div class="pdf-btn-out">
<div class="pdf-btn">
<div class="pdf-inner">
<a href="' . $link['url'] .'" target="' . $link['target'] .'">' . $link['title'] .'</a>
</div>
</div>
</div>'
;
}
add_shortcode( 'notna_slika_btn', 'notna_slika_link' );
function notna_slika_link() {
$link = get_field('prikaz_notne_slike');
if ($link) {
$link_url = $link['url'];
$link_title = $link['title'];
$link_target = $link['target'] ? $link['target'] : '_self';
return
'<div class="pdf-btn-out">
<div class="pdf-btn">
<div class="pdf-inner">
<a href="' . $link['url'] .'" target="' . $link['target'] .'">' . $link['title'] .'</a>
</div>
</div>
</div>'
;
} else {
/// return what you want if no link is entered
}
}
Works like a charm. Thank you very much.