Hi,
I have a gallery plugin, and when I put the shortcode for my gallery in an WYSIWYG editor, it works fine. But I want the editor to only put in a shortcode (nothing else), so I would like to use a text field so a user can only enter the shortcode.
I did that, but how would I display that on my page now? Simply going:
<?php the_field(‘cf_custom_gallery’); ?>
is not working for me. (where cf_custom_gallery is the name of my text input field)
Anyone know how to display it, or another way to approach this?
Thanks,
JC
Hi all, here is an update.
I am using a text input field to add a shortcode. My shortcode looks like this:
[fancygallery id="1" album="6"]
in my php page, I am doing this:
<?php
$myvalue = get_field( "cf_custom_gallery" );
echo do_shortcode("$myvalue");
?>
but it is not outputting. If I manually do this:
<?php
echo do_shortcode('[fancygallery id="1" album="6"]');
?>
it works.
ANy suggestions ?
Thanks,
JC
Hi @joecannes
Your code looks good, but you don’t need the double quotes around the "$myvalue"
variable.
Perhaps the value is not being loaded. You can debug the data like so:
$myvalue = get_field( "cf_custom_gallery" );
echo '<pre>';
print_r( $myvalue );
echo '</pre>';
die;
Hi Elliott,
Thanks for your suggestion, I did try that, and the value was appearing. But I actually got it working!
The problem was the double quotes in the shortcode.
[fancygallery id="1" album="6"]
If I removed the double quotes, it worked.
[fancygallery id=1 album=6]
But I could not tell the client to always delete the double quotes when inserting a shortcode, so I kept the short code as-is:
[fancygallery id="1" album="6"]
and within advanced custom fields, I changed the format setting for the Text field type to “Convert HTML into tags” instead of “No formatting”
It works now!
Thanks,
JC
Sorry, feel free to remove this post