admin管理员组文章数量:1130349
I have this iframe and JavaScript embedded in a post:
<iframe onload="fa_iframeresize.do(this);" src=".php?tp=dif&cl=beleggen&h=1&wf=19370&country=NL" scrolling="no" width="100%" style="padding:0px;margin:0px;border-width:0px;" frameborder="0">
</iframe>
<script type="text/javascript" src="//example/iframeResizeMe.min.js.gz"></script>
But whenever I go to the visual editor the HTML gets changed tiny bit in such a way that example's code can't handle it anymore:
<iframe style="padding: 0px; margin: 0px; border-width: 0px;" src=".php?tp=dif&cl=beleggen&h=1&wf=19370&country=NL" width="100%" frameborder="0" scrolling="no">
</iframe>
<script type="text/javascript" src="//example/iframeResizeMe.min.js.gz"></script>
Is there a way to keep the visual editor from changing a chunk HTML?
I tried the iframe extension but that didn't really handle it properly. I'd also like to avoid creating my own plugin for this.
Ideally I'd like e.g. <!-- NOREFORMAT --><iframe></iframe><script></script><!-- /NOREFORMAT -->.
I have this iframe and JavaScript embedded in a post:
<iframe onload="fa_iframeresize.do(this);" src="https://example/calc.php?tp=dif&cl=beleggen&h=1&wf=19370&country=NL" scrolling="no" width="100%" style="padding:0px;margin:0px;border-width:0px;" frameborder="0">
</iframe>
<script type="text/javascript" src="//example/iframeResizeMe.min.js.gz"></script>
But whenever I go to the visual editor the HTML gets changed tiny bit in such a way that example's code can't handle it anymore:
<iframe style="padding: 0px; margin: 0px; border-width: 0px;" src="https://example/calc.php?tp=dif&cl=beleggen&h=1&wf=19370&country=NL" width="100%" frameborder="0" scrolling="no">
</iframe>
<script type="text/javascript" src="//example/iframeResizeMe.min.js.gz"></script>
Is there a way to keep the visual editor from changing a chunk HTML?
I tried the iframe extension but that didn't really handle it properly. I'd also like to avoid creating my own plugin for this.
Ideally I'd like e.g. <!-- NOREFORMAT --><iframe></iframe><script></script><!-- /NOREFORMAT -->.
1 Answer
Reset to default 1 +50 add_shortcode('custom_iframe_shortcode', 'build_iframe');
function build_iframe($atts) {
$defaults = array(
'source' => 'https://example/calc.php?tp=dif&cl=beleggen&h=1&wf=19370&country=NL',
'script_source' => '//example/iframeResizeMe.min.js.gz'
);
$args = shortcode_atts($defaults, $atts);
ob_start(); ?>
<iframe onload="fa_iframeresize.do(this);" src="<?php echo $args['source']; ?>" scrolling="no" width="100%" style="padding:0px;margin:0px;border-width:0px;" frameborder="0">
</iframe>
<script type="text/javascript" src="<?php echo $args['script_source']; ?>"></script>
<?php return ob_get_clean();
}
then call this like [build_iframe] or [build_iframe source="https://blah" script_source="https://blah/blah.js']
I have this iframe and JavaScript embedded in a post:
<iframe onload="fa_iframeresize.do(this);" src=".php?tp=dif&cl=beleggen&h=1&wf=19370&country=NL" scrolling="no" width="100%" style="padding:0px;margin:0px;border-width:0px;" frameborder="0">
</iframe>
<script type="text/javascript" src="//example/iframeResizeMe.min.js.gz"></script>
But whenever I go to the visual editor the HTML gets changed tiny bit in such a way that example's code can't handle it anymore:
<iframe style="padding: 0px; margin: 0px; border-width: 0px;" src=".php?tp=dif&cl=beleggen&h=1&wf=19370&country=NL" width="100%" frameborder="0" scrolling="no">
</iframe>
<script type="text/javascript" src="//example/iframeResizeMe.min.js.gz"></script>
Is there a way to keep the visual editor from changing a chunk HTML?
I tried the iframe extension but that didn't really handle it properly. I'd also like to avoid creating my own plugin for this.
Ideally I'd like e.g. <!-- NOREFORMAT --><iframe></iframe><script></script><!-- /NOREFORMAT -->.
I have this iframe and JavaScript embedded in a post:
<iframe onload="fa_iframeresize.do(this);" src="https://example/calc.php?tp=dif&cl=beleggen&h=1&wf=19370&country=NL" scrolling="no" width="100%" style="padding:0px;margin:0px;border-width:0px;" frameborder="0">
</iframe>
<script type="text/javascript" src="//example/iframeResizeMe.min.js.gz"></script>
But whenever I go to the visual editor the HTML gets changed tiny bit in such a way that example's code can't handle it anymore:
<iframe style="padding: 0px; margin: 0px; border-width: 0px;" src="https://example/calc.php?tp=dif&cl=beleggen&h=1&wf=19370&country=NL" width="100%" frameborder="0" scrolling="no">
</iframe>
<script type="text/javascript" src="//example/iframeResizeMe.min.js.gz"></script>
Is there a way to keep the visual editor from changing a chunk HTML?
I tried the iframe extension but that didn't really handle it properly. I'd also like to avoid creating my own plugin for this.
Ideally I'd like e.g. <!-- NOREFORMAT --><iframe></iframe><script></script><!-- /NOREFORMAT -->.
-
2
Note that the only reason you're able to insert a raw iframe at all is because you're an administrator with the dangerous
unfiltered_htmlcapability. Use an iframe shortcode instead, and then enqueue a script that hooks on to the onLoad of all iframes instead of adding dangerous inline JS script attributes – Tom J Nowell ♦ Commented Sep 18, 2018 at 13:15 - It is possible to allow iframe tag for the tinyMCE editor, see wordpress.stackexchange/a/3067/170 However I think you should create a plugin that add a shortcode to add this inside the content. SO you get a more valid content, easier to maintain if you will change this code or remove them from the content in the future. – bueltge Commented Dec 12, 2018 at 12:55
- visit link see..wordpress.stackexchange/questions/243780/… – Ashvin Monpara Commented Dec 14, 2018 at 4:37
1 Answer
Reset to default 1 +50 add_shortcode('custom_iframe_shortcode', 'build_iframe');
function build_iframe($atts) {
$defaults = array(
'source' => 'https://example/calc.php?tp=dif&cl=beleggen&h=1&wf=19370&country=NL',
'script_source' => '//example/iframeResizeMe.min.js.gz'
);
$args = shortcode_atts($defaults, $atts);
ob_start(); ?>
<iframe onload="fa_iframeresize.do(this);" src="<?php echo $args['source']; ?>" scrolling="no" width="100%" style="padding:0px;margin:0px;border-width:0px;" frameborder="0">
</iframe>
<script type="text/javascript" src="<?php echo $args['script_source']; ?>"></script>
<?php return ob_get_clean();
}
then call this like [build_iframe] or [build_iframe source="https://blah" script_source="https://blah/blah.js']
本文标签: How to ensure the visual editor doesn39t ruin my iframe
版权声明:本文标题:How to ensure the visual editor doesn't ruin my iframe? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749090768a2314482.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


unfiltered_htmlcapability. Use an iframe shortcode instead, and then enqueue a script that hooks on to the onLoad of all iframes instead of adding dangerous inline JS script attributes – Tom J Nowell ♦ Commented Sep 18, 2018 at 13:15