I am trying to get a url to a custom field to display only if it is not empty. could someone please explain what i am doing wrong so that i may learn from this, i am new to php and Im really struggling to figure this out.
example 1 displays the link whether field is empty or not however when it is empty, it links to the blog post instead of the link picker field, when it is not empty the link points to the correct field.
<div class="my_link"> <?php if($mylink = get_field('article_link') ): ?> <div class="your_custom_class"> <a href="<?php echo ($mylink[url]); ?>"target="">Link to Article</a></div> <?php endif; ?> </div>
example 2 only shows if the field is not empty and does not show when the field is empty but it is not a url link to the custom field and just echos the correct url to the link.
<?php if($mylink = get_field('article_link') ): ?> <?php echo($mylink[url]); ?> <?php endif; ?>
Thankyou very much for your time