Output shortcode from a custom field
- This topic has 9 replies, 4 voices, and was last updated 9 months, 3 weeks ago by
saint.
-
AuthorPosts
-
April 26, 2021 at 3:58 AM #27632
Amanda RM
ParticipantHello.
I have a custom field set up where a unique shortcode would be entered for each post. What I've tried so far will not output the rendering of the shortcode. Instead, on the frontend, the text of the unique shortcode for that post is visible. I'm using Oxygen Builder.
How it is set up:
- I have a custom field with the ID of checkout-form-shortcode. This field group is applied to the Products post type.
- In the template assigned to Products, I have a shortcode element with the following shortcode [rwmb_meta id="checkout-form-shortcode"]
- On the frontend, the text of the shortcode that was entered in that custom field for the specific post is displayed.Can you possibly point to where I may be doing this incorrectly? I was using ACF before purchasing Meta Box, and was able to make this work using php.
Thank you!
April 26, 2021 at 11:03 AM #27641Long Nguyen
ModeratorHi,
Thank you for reaching out.
Currently, the helper shortcode
[rwmb_meta]
does not support render shortcodes in the field value. If you use the field type WYSIWYG, please run it via PHP code. Get more details on this documentation https://docs.metabox.io/fields/wysiwyg/#template-usageMay 1, 2021 at 5:05 AM #27799Amanda RM
ParticipantCan you please tell me how to make this work?
Would I put this in a code block element? If so, would I replace the custom field ID with the one I've created?
$value = rwmb_meta( $field_id );
echo do_shortcode( wpautop( $value ) );I need some more support to get this to work. Thanks.
May 2, 2021 at 9:37 AM #27816Long Nguyen
ModeratorHi,
You need to wrap the code in a function, just like
function my_custom_function() { $value = rwmb_meta( 'checkout-form-shortcode' ); echo do_shortcode( wpautop( $value ) ); }
apply the function with the plugin Code Snippets or code block as you want. Then show the field value with PHP Function Return Value.
May 2, 2021 at 11:48 PM #27834Amanda RM
ParticipantThank you for your reply.
I am getting the return of 'function does not exist'.
I have this code snippet created: https://moveyourfamilyabroad.com/wp-content/uploads/2021/05/Screenshot-2021-05-02-104348.png
I used the PHP Function Return Value. I am unclear what is entered in the argument line. I've tried entering various values with all the same result: https://moveyourfamilyabroad.com/wp-content/uploads/2021/05/Screenshot-2021-05-02-104431.png
Can you tell me please if I'm entering the wrong info into the Php return value option or where else I may be going wrong? Thanks!
May 3, 2021 at 11:14 PM #27858Long Nguyen
ModeratorHi,
Did you enable the snippet? Screenshot https://share.getcloudapp.com/d5u12RZG
There are no arguments need to pass to the custom function so you can remove it.
[oxygen data='phpfunction' function='my_custom_function']
May 4, 2021 at 12:08 AM #27864Amanda RM
ParticipantAhh - yes, that detail was missed on my end. Thank you so much! It's working now :). Thank you for your patience!!
May 25, 2024 at 12:21 AM #45526Keith Cross
ParticipantHello,
I'm trying to do this as well. I have this function:function render_shortcode() {
$value = rwmb_meta( 'presto_video_shortcode' );
echo do_shortcode( wpautop( $value ) );
}the shortcode value is input to the WYSIWYG field:
https://drive.google.com/open?id=13GWZL7k9qLUzgyCaABrUqonh9PRApO_Y&usp=drive_fs
The code is turned on in WPCodeBox:
https://drive.google.com/open?id=13HTHCjKId9AEXOj24Yj0YRr0aGX8CWxK&usp=drive_fs
I've checked to make sure the code signature in Bricks is valid and is added to the theme.
I've got two elements in a query loop: Code and Shortcode and neither are rendering the shortcode.
The Code elmement loads, but no code is rendered. The shortcode doesn't load. I've got my_custom_function for "hello world" in there to make sure I know echo is working.
I must be doing something simply wrong...any suggestions would be very much appreciated.
May 25, 2024 at 12:33 AM #45527Keith Cross
ParticipantMeant to include a link: https://artsworcesterdev.milkrow.com/exhibition/solo-show-name-title/
June 25, 2024 at 8:31 AM #45699saint
ParticipantSame here, can MB support provide some insight into how this can be achieved? Typically I've included shortcodes inside a WYSIWYG and displayed them with no issues, but not sure how to best approach this in Metabox.
-
AuthorPosts
- You must be logged in to reply to this topic.