• Resolved ezoulou

    (@ezoulou)


    Hi,

    First of all, thanks for the great plugin.

    I want to rewrite the output of my field (an URL) as an iframe source. But the iframe does not show on frontend. Here is my code :

    function ( $content, $attributes, $block, $post_id ) {
    return '<iframe src="'.$content.'"> </iframe>';
    }

    Any tips?

    PS : To be precise I must say other fields render without problem.

    • This topic was modified 1 year, 5 months ago by ezoulou.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Phi Phan

    (@mr2p)

    Hi @ezoulou,

    The value of the block will be escaped by using the wp_kses function. Here is the code :

    wp_kses( $content, wp_kses_allowed_html( 'post' ) )

    By default, iframe will be removed from the content. To display it, you have to add it to the list of allowed tags. Here is an example code to allow displaying iframe::

    add_filter(
      'wp_kses_allowed_html',
      function ( $allowedposttags, $context ) {
        if ( 'post' === $context ) {
          $allowedposttags['iframe'] = array(
            'src'             => true,
            'height'          => true,
            'width'           => true,
            'frameborder'     => true,
            'allowfullscreen' => true,
          );
        }
    
        return $allowedposttags;
      },
      10,
      2
    );

    Thank you for your feedback. Please let me know if you need further help.

    Phi.

    • This reply was modified 1 year, 5 months ago by Phi Phan.
    Thread Starter ezoulou

    (@ezoulou)

    Thanks yo so much for the quick answer, I’ll give it a try.

    By the way, your fantastic plugin also solved my bug (same as mentioned here : https://github.com/WordPress/gutenberg/issues/35676#issuecomment-1567481399)

    Plugin Author Phi Phan

    (@mr2p)

    You’re welcome. I’m glad you found it useful.

    Thanks, Phi.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Iframe’ is closed to new replies.