Search code examples
phpwordpressshortcode

How do I use a PHP Short Code from custom field as an href link on Wordpress?


On my wordpress page (which I will use as a template to duplicate) I need to use a custom field 'dropbox' as an href url.

I created a PHP Code Snippet (shortcode) to use as a replacement for the url: [xyz-ips snippet="dropbox"]

Here is the PHP within the shortcode:

<?php the_field('dropbox'); ?>

Here is the code on the page:

<a href="[xyz-ips snippet=" dropbox"]"="" target="_new">download the documents</a>

This short code will not pass the url from custom field to the href. Any thoughts?

Thanks in advance.


Solution

  • So it turns out there is a specific way to call url custom fields (ACF). I inserted the below code into a PHP Code shortcode. This worked like a charm!

        <?php 
    
    $link = get_field('dropbox');
    
    if( $link ): ?>
    
        <a class="button" href="<?php echo $link; ?>" target="_new">download documents</a>
    
    <?php endif; ?>