Support

Account

Home Forums Front-end Issues Displaying A button to Download a PDF (File)

Helping

Displaying A button to Download a PDF (File)

  • Hello there!

    I’ve been digging around for 2 days and I still didn’t solve this problem:

    As I’m creating an online catalog, I would like to dispay a button on each product page that’s linked to their unique PDF file (Datasheet) that I can define in backend with the File Field Type.

    Everything is going as planned, Here’s a look at the “setup”:

    ACF Setup

    but no matter how I pass the request, I always get a wrong HTML link like so:

    Here’s the code to retrieve the File Field Type

    <?php if( get_field('fiche_pdf') ): 
    $link= the_field('fiche_pdf');?>
              <a href="<?php echo $link;  ?>" target="_blank"><strong>Brochure</strong></a>
            <?php
            endif;?>

    Here’s the result

    http…/shop/product-name/<?php%20echo%20$link;%20%20?>

    I’ve tried with a Link field type, same result:

    Here’s the Code (as simple as possible):

    <a href="<?php echo esc_url($link); ?>">click here</a>

    And the result:

    http…/shop/product-name/<?php%20echo%20esc_url($link);%20?>

    I think that it’s related to the fact that I can’t execute php, because the code work if I use XYZ PHP CODE (Php shortcode plugin)

    Truly, the best goal for me is to be able to pass the url to an Advanced button (from WPBakery’s Mega Addons)

    But this is another problem…

    You can take a look at this here: http://mmpi.mrfortas.com/produit/compresseur-portatif-c-41/

    Thank you for your help 🙂

  • 
    $link= get_field('fiche_pdf');
    

    the_field() echos the value, get_field() gets the value. They cannot be user interchangeably.

    As far as the plugin and why it’s butchering it, I don’t know.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.