2011-10-21 36 views
1

I have a fairly straight forward shortcode for making a quote breakout box which is called as:WordPress的汽提<a href> from shortcodes

[jasminesays quote="blah de blah"] 

Dead easy. However when I try and put a link inside it wordpress won't return the quote at all. All other HTML that I've tried seems fine, it only seems to fall over with something like:

[jasminesays quote="blah <a href="#">de</a> blah"] 

Something like

[jasminesays quote="blah <p>de</p> blah"] 

works fine.

The code to process the shortcode is:

function mm_jasmineSays($atts) { 
extract(shortcode_atts(array( 
     "quote" => '', 
     ), $atts)); 

return '<link href="'.get_bloginfo('template_directory').'/css/shortcodes.css" rel="stylesheet" type="text/css" /> 
     <div class="jasmine-says"> 
      <h2>Jasmine says...</h2> 
      <div class="jasmine-says-quote"> 
       <p><img src="'.get_bloginfo('template_directory').'/imgs/shortcodes/quote-1.jpg" /></p> 
       <p class="quote">'.$quote.'</p> 
       <p><img src="'.get_bloginfo('template_directory').'/imgs/shortcodes/quote-2.jpg" /></p> 
      </div> 
     </div>'; 
} 
add_shortcode('jasminesays', 'mm_jasmineSays'); 

but I don't think this is the problem, I'm guessing wordpress is filtering certain things out somewhere and I need to disable this. Anyone have any ideas?

Thanks for any help.

回答

1

From WordPress Codex

一個短碼處理函數的返回值被插入到 交內容輸出代替短碼宏。請記住使用 返回而不是回顯 - 任何回顯的內容都將輸出到 瀏覽器,但它不會顯示在頁面上的正確位置。

在wpautop和wptexturize後格式化 已被應用(但請參閱下面的註釋約2.5.0和2.5.1 區別)後解析短代碼。這意味着您的短碼輸出HTML將不會自動應用曲線報價,添加p和br標籤等等 。如果你確實希望你的短代碼輸出被格式化,當你從短代碼處理程序返回輸出 時,你應該直接調用wpautop()或wptexturize()。

wpautop識別短代碼語法,並將嘗試不包裝p或 br標籤圍繞自己單獨排隊的短代碼。 旨在以這種方式使用的短代碼應確保 輸出包裝在適當的塊標記(如p或div)中。

+0

加入 $ quote = apply_filters('the_content',$ quote) ; 到短代碼功能似乎沒有工作,這似乎很奇怪。它似乎是專門挑選標籤而沒有別的。 – artparks

0

不知道這是否有幫助,但你有沒有嘗試將外引號改爲單引號?

[jasminesays quote='blah <a href="#">de</a> blah'] 

或刪除內部引號?

[jasminesays quote="blah <a href=#>de</a> blah"] 
0

爲什麼不添加url選項到短代碼?

喜歡的東西加入:

function mm_jasmineSays($atts) { 
extract(shortcode_atts(array( 
"quote" => '', 
"url" => '', 
), $atts)); 

,然後加入

<a href="'.$url.'"> <h2>Jasmine says...</h2></a> 

也許這可能工作.. 或使用$輸出,而不是像返回:

global $post; 
$output .= '<div class="jasmine-says">'; 
if($quote !== '') 
$output .= '<a href="'.$url.'"><h2>Jasmine says...</h2>'; 
     $output .= '<div class="jasmine-says-quote">' 
      $output .='<p><img src="'.get_bloginfo('template_directory').'/imgs/shortcodes/quote-1.jpg" /></p>'; 
      $output .='<p class="quote">'.$quote.'</p>'; 
      $output .='<p><img src="'.get_bloginfo('template_directory').'/imgs/shortcodes/quote-2.jpg" /></p>'; 
     $output .='</div>'; 
    $output .='</div>'; 
相關問題