最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

embed - Why does my custom html code (for a donation form) appear in a preview but not in the published post?

programmeradmin5浏览0评论

I have tried to add the following code using a 'Custom html' block (to embed a GiveNow donation form). It shows as a preview on the page however when I attempt to view it on the live website, it is not visible:

<div style="padding:1px;max-width: 700px"><iframe class="gn-iframe" src="; height="870" style="width: 100%" frameborder="0"></iframe></div>

I have read through other help responses to similar issues but can't figure out what I'm doing wrong.

Thanks in advance, Lauryn

I have tried to add the following code using a 'Custom html' block (to embed a GiveNow donation form). It shows as a preview on the page however when I attempt to view it on the live website, it is not visible:

<div style="padding:1px;max-width: 700px"><iframe class="gn-iframe" src="https://www.givenow.au/embed/Y2F1c2VpZD04MTImZG9tYWluPWxpZmUtZ2F0ZS5vcmcmdG9rZW49ODEyOjZhMGFhNmQyYzZiZTM2ZTk%3D" height="870" style="width: 100%" frameborder="0"></iframe></div>

I have read through other help responses to similar issues but can't figure out what I'm doing wrong.

Thanks in advance, Lauryn

Share Improve this question edited Jul 10, 2020 at 1:24 Jacob Peattie 44.1k10 gold badges50 silver badges64 bronze badges asked Jul 10, 2020 at 1:17 Life-Gate IncLife-Gate Inc 1 5
  • 1 It's possible that it's being hidden or squashed by your theme. I you inspect the HTML of the published page, can you see these elements, or are they missing entirely? – Jacob Peattie Commented Jul 10, 2020 at 1:25
  • I'll check! Thanks for the tip Jacob :) – Life-Gate Inc Commented Jul 10, 2020 at 3:23
  • Hi Jacob, I'm not brilliant with this stuff, but it looks to me like the coding I embedded is missing entirely from the HTML of the published page :/ – Life-Gate Inc Commented Jul 10, 2020 at 3:36
  • When you save the post and come back is the HTML block empty, or is it still saved with the post? – Jacob Peattie Commented Jul 10, 2020 at 5:34
  • Hi Jacob, when you save the post, exit it and then go back in, the above code is changed in the HTML block and all that remains is this: <div style="padding:1px;max-width:700px;"></div> – Life-Gate Inc Commented Jul 17, 2020 at 2:00
Add a comment  | 

1 Answer 1

Reset to default 0

WordPress strips out iframes by default. Which is why you can see it in the editor but not when you try to save/publish this on your site.

Try enabling iframes by adding this to your themes functions.php file

    /**
     * Add iFrame to allowed wp_kses_post tags
     *
     * @param string $tags Allowed tags, attributes, and/or entities.
     * @param string $context Context to judge allowed tags by. Allowed values are 'post',
     *
     * @return mixed
     */

add_filter( 'wp_kses_allowed_html', 'allow_iframe_in_editor', 10, 2 );
    
function allow_iframe_in_editor( $tags, $context ) {
        if( 'post' === $context ) {
            $tags['iframe'] = array(
                'allowfullscreen' => TRUE,
                'frameborder' => TRUE,
                'height' => TRUE,
                'src' => TRUE,
                'style' => TRUE,
                'width' => TRUE,
            );
        }
        return $tags;
    }
发布评论

评论列表(0)

  1. 暂无评论