Site logo

[Resolved] ACF Shortcodes

Home Forums Support [Resolved] ACF Shortcodes

Home Forums Support ACF Shortcodes

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #496003
    Beau

    I’m trying to create a simple shortcode that pulls a file’s URL from an Advance Custom Field File field (like a PDF) and creates a standard text link with it.

    So for my client, they can upload new PDF and then it’s automatically added to the text link.

    What is the best way to do this using functions.php and shortcodes?

    #496395
    Tom
    Lead Developer
    Lead Developer

    If it’s for your client to add to their pages as needed, I would use a shortcode.

    Let me know if you need more info 🙂

    #498040
    Beau

    This is driving me bananas. It is not working correctly and it is also placing the text from the shortcode in the top left corner of the page.

    `function dinner_menu() {
    echo ‘<a href=\”‘;
    echo the_field(‘dinner’);
    echo ‘\”>Dinner Menu‘;
    }
    add_shortcode(‘dinner’, ‘dinner_menu’);’

    The shortcode field is a File and the return value is a File URL of a PDF uploaded by WordPress. I know this is more of an ACF issues, but can you help? Thanks in advance.

    URL: https://staging.thatplaceinogunquit.com/menus/

    #498374
    Tom
    Lead Developer
    Lead Developer

    You need to use output buffering in your shortcode if you’re echoing HTML: https://stackoverflow.com/a/42591351/2391422

    So at the top: ob_start();

    And at the end: return ob_get_clean();

    #498731
    Beau

    Got it, thanks!

    #498994
    Tom
    Lead Developer
    Lead Developer

    You’re welcome 🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.