Inject HTML through custom field - Sanitization

Support MB Builder Inject HTML through custom field - SanitizationResolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #39377
    Stockton FisherStockton Fisher
    Participant

    Hey team,

    I'm trying to include a custom textarea field in my custom post type that will allow the user to input any HTML into the field that would then be rendered in a certain spot on the page.

    My current set up (not working)

    1. Custom Field:
    - Defined as a textarea type https://share.getcloudapp.com/v1uERGrR
    - Sanitization set to "none" https://share.getcloudapp.com/DOukNLQn

    2. In the Custom Post:
    - HTML is added to the custom field in the custom post https://share.getcloudapp.com/bLuODNjN

    3. Page Template (Bricks):
    - Using code block to echo the value of the custom field https://share.getcloudapp.com/llugvenl
    <?php echo '{mb_recipes_embed_code}' ?>

    4. Result:
    - On the page the out still appears to be sanitized. The HTML no longer has the <script> tags. https://share.getcloudapp.com/2Nu6RQld

    How do I make this work?

    #39392
    PeterPeter
    Moderator

    Hello there,

    Can you please let me know where do you create the shortcode mb_recipes_embed_code? Please try to use the helper function rwmb_meta() to output the field value.

    echo rwmb_meta( 'embed_code', '', 123 );

    where 123 is the post ID. Read more on the documentation https://docs.metabox.io/functions/rwmb-meta/

    #39401
    Stockton FisherStockton Fisher
    Participant

    Thank you for the excellent help, Peter!

    I gave that a try and now the output is just blank.

    Setting in Code element: https://share.getcloudapp.com/xQuOZ0Bz
    <?php echo rwmb_meta('embed_code','','{post_id}'); ?>

    The original shortcode is directly from Bricks Builder reading that field. https://share.getcloudapp.com/X6u5BzxA

    Thank you for being so supportive.

    #39409
    Stockton FisherStockton Fisher
    Participant

    After much trial and error, the solution here was to just leave the 3rd argument blank.
    https://share.getcloudapp.com/12uR5QLg

    <?php echo rwmb_meta('embed_code','',''); ?>

    #39427
    PeterPeter
    Moderator

    Hello,

    If the third parameter (post ID) is blank, that means the current post ID is used. In this case, you can just use the field ID as the first parameter.

    <?php echo rwmb_meta('embed_code'); ?>

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