Support Forum
Shortcodes such as the following...
[gravityform id="1" title="false" description="false" ajax="true"]
...are not rendering when inserted into Metabox textarea
or wysiwyg
fields.
Is there something special I should be specifying during field definition? Or in the template that displays the field content?
Hello there,
If you want to render the shortcode added to the WYSIWYG field value, please use the PHP code
echo do_shortcode( $field_value );
Read more on the documentation https://docs.metabox.io/fields/wysiwyg/#template-usage
Interesting, thank you.
This indeed works as expected, but it raises a question: Will this approach have any deleterious effects if $field_value
includes non-wysiwyg
fields?
I ask this, because our templates assemble together the values of different fields (and field types), into a single payload that may (or may not) include wysiwyg
fields. And, of course, it would be better to use this technique once at the final render instead of every place in which a wysiwyg
is called, especially since we switch wysiwyg
availability on and off in some cases with conditional logic.
Related question: We need to be able to render shortcodes inserted into textarea
fields as well, but I don't see a note like the above in the textarea
docs. Is this technique expected to also work with textarea
fields?
Hello,
Yes, if you use the textarea field and add the shortcode, you need to bypass the sanitization to save the value. Then you can render the shortcode as well as WYSIWYG field.
Please read more on the documentation https://docs.metabox.io/sanitization/
Hey Peter, where do I add the $value = rwmb_meta( 'my_field_id' );
echo do_shortcode( wpautop( $value ) );
in the custom field to display the shortcodes? Sorry, I'm confused with the documentation linked above and I'm not familiar with PHP
Hello Josh,
You need to add the code to the template file that displays post content in your theme folder, please read more here https://docs.metabox.io/displaying-fields-with-code/
If you are not able to accomplish the task, please contact us here https://metabox.io/contact/ with a customization service request. Our development team will help you with a small fee.