Custom Fields
Re-Envisioned
Support MB User Meta Add an iframe embed code in a user custom field, display via shortcode in post

  • Creator
    Topic
  • #28661
    Lucas
    Participant

    I'm using Client Portal to create portal pages for each user. With User Meta, I added a text field with an iframe embed code.
    I wanted to display that embed on the front end based on the user's login. I used a shortcode in the post content:
    [rwmb_meta id="custom_field_id"]
    However, nothing displays. Any suggestions?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #28681
    Long Nguyen
    Moderator

    Hi Lucas,

    The text field has the default sanitization callback sanitize_text_field which does not allow any tags.

    You can bypass this sanitization by using setting

    'sanitize_callback' => 'none'

    Get more details on this documentation https://docs.metabox.io/sanitization/

    #28709
    Lucas
    Participant

    Thank you!
    I added "none" but the iframe didn't display.
    I have also tried adding a simple url, then writing the iframe into the page with the shortcode embedded: https://pastebin.com/2ttVGpPi
    However, that embeds the current page nested infinitely.
    I think I'm missing something basic about how to pull a url from a custom field with a shortcode.

    #28720
    Long Nguyen
    Moderator

    Hi Lucas,

    The field text or textarea content does not support parsing the shortcode in the attribute URL. If you want to do that, please use the PHP code in your template file

    echo '<iframe src='. do_shortcode( '[rwmb_meta id="field_url" object_id=1 object_type="user"]' ) .' width="680" height="480" allowfullscreen></iframe>';
    

    Or simply add the tag <iframe> in the field WYSIWYG content with attribute URL

    <iframe src="https://www.youtube.com/embed/nmRKrf0JguY" width="680" height="480" allowfullscreen></iframe>
    

    then use the shortcode to show the user field value

    [rwmb_meta id="field_url" object_id=1 object_type="user"]

    Get more shortcode details here https://docs.metabox.io/shortcode/

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