Archived topic
ACF Shortcodes
5 replies · Started by Beau on February 14, 2018
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?
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 :)
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.
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();
Got it, thanks!
You're welcome :)