Wordpress中的iframe [英] iframes in Wordpress

查看:296
本文介绍了Wordpress中的iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试生成一些可嵌入的iframe代码,以便用户可以在博客中包含代码以显示我计划提供的内容。现在,我想提供的内容只是一个网站。我试图在Wordpress博客上使用以下代码:

I am trying to generate some embeddable iframe code so a user can include the code on a blog to display content I'm planning to deliver. Right now the content I'm trying to deliver is just a website. I am trying to use the following code on a Wordpress blog:

<iframe width="420" height="315" src="http://www.cnn.com" frameborder="0"></iframe>

然而,当查看页面时,Wordpress只会输出http://www.cnn的链接。 com基于以下html。

However when the page is viewed Wordpress simply outputs a link for "http://www.cnn.com" based on the following html.

<a href="http://www.cnn.com">http://www.cnn.com</a>

也就是说,如果我使用Youtube生成的iframe代码,则iframe加载正常。例如:

That said, if I use Youtube generated iframe code, the iframe loads fine. For example:

<iframe width="420" height="315" src="http://www.youtube.com/embed/_OBlgSz8sSM" frameborder="0" allowfullscreen></iframe>

结果为:

<iframe class='youtube-player' type='text/html' width='420' height='315' src='http://www.youtube.com/embed/_OBlgSz8sSM?version=3&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;wmode=transparent' frameborder='0'></iframe>

知道Youtube正在做什么来启用此功能,或者更普遍的是如何使我的简单iframe工作。

Any idea what Youtube is doing to enable this functionality or more generally how to get my simply iframe to work.

推荐答案

创建短代码是我解决这个问题的方法。它绕过WYSIWYG编辑器并将html放在页面中。

Creating a shortcode is the way I get around this problem. It bypasses the WYSIWYG editor and puts the html in the page.

我会像这样接近它。

将它添加到你的functions.php文件中:

Add this to your functions.php file:

function add_iframe($atts) {
    extract(shortcode_atts(array(
    'src' => '/'
    ), $atts));
  $theframe = '<iframe src="'.$src.'" width="420" height="315" frameborder="0"></iframe>';
  return $theframe;
}
add_shortcode('iframe', 'add_iframe');

用法:

添加[iframe src = http://thesiteyouwanttoshow.com]到您希望iframe显示的内容。

Add [iframe src=http://thesiteyouwanttoshow.com] to the content where you want the iframe to show.

这篇关于Wordpress中的iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆