2011-10-21 34 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>'; 
相关问题