2012-03-04 47 views
0

基本上我想創建一個短代碼,將iframe添加到apost/page等中。 我嘗試了以下操作,但出於某種原因框架顯示爲空白。WordPress的自定義iframe短代碼無法返回iframe

//custom added functions 
add_shortcode('wrap', 'addWrapper'); 
function addWrapper($atts,$content=null){ 
    extract(shortcode_atts(array(
     "src" => 'http://google.com', 
     "height" => '300', 
     "width" => '400', 
     "scrolling" => 'auto' 
    ), $atts)); 

    return '<div id="iwrapper"> 
     <iframe src="'.$src.'" height="'.$height.'" width="'.$width.'" scrolling="'.$scrolling.'"></iframe> 
     </div>'; 

如果我嘗試返回其他任何內容,例如簡單的HELLO WORLD文本,它將返回正常。爲什麼WordPress的空白iframe?我試圖手動發送一個iframe過,但沒有(<iframe width="150" height="300" src="http://www.youtube.com" frameborder="0" type="text/html"></iframe>)..

當我使用Firebug debbug我沒有看到任何錯誤:S

<div id="iwrapper"> 
<iframe src="http://google.com" height="300" width="400" scrolling="auto"/> 
</div> 

回答

0

的WordPress有一些安全限制,將刪除I幀。上面的例子很難看出你是如何在iframe中加載的。你在製作一個wordpress插件嗎?

+0

實際上,我剛剛打開了functions.php(其中一個標準主題,如二十一個主題),並將其鍵入。我想先嚐試使其工作,然後嘗試構建一個插件它 – George 2012-03-04 15:59:13

+0

我已經下載了一些其他的iframe插件,看看他們是如何工作的,但他們中的大多數只是像我在做的那樣返回iframe代碼。有沒有辦法繞過這些安全限制? – George 2012-03-04 16:04:52

+0

此外,如果不是網頁,我添加一個視頻元素作爲源,它顯示得很好。例如,如果我把src = http://www.youtube.com/embed/iHJoMPBgkV0,它顯示,但如果我把例如:www.google.com作爲來源,它不是:S – George 2012-03-04 16:27:59