让WordPress的评论/回复内容也支持短代码ShortCodes

什么是短代码?

参看博客文章《在wordpress中使用短代码提高工作效率

让评论/回复也支持短代码

玩过短代码么?是否遇到在访客的评论中短代码是无效的?今天介绍一个方法让WordPress的评论也支持短代码ShorCodes,这样也提供了评论/回复者的效率了哦。比如我们已经添加了一个ifans的短代码(也称简码)到WordPress,那么现在我们要这个ifans的短代码也支持评论回复,我们就需要添加以下代码到主题的functions中。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*让评论也支持短代码*/

function init_common_shortcodes() {
  add_shortcode('ifans', 'ifans');//这个地方要注意根据你添加的短代码名称修改
}
 
function init_comment_shortcodes() {
  remove_all_shortcodes();
  init_common_shortcodes();
  add_filter('comment_text', 'do_shortcode');
}
 
init_common_shortcodes();
add_filter('comments_template', 'init_comment_shortcodes');

Leave a Reply

You must be logged in to post a comment.

RSS feed for comments on this post. TrackBack URL