如何在每次创建注释时自动化在wordpress中添加注释链接的过程

如何在每次创建注释时自动化在wordpress中添加注释链接的过程

问题描述:

so we are making a wordpress site that automatically adds a link to a comment every time a comment is created. The theme we are using is html5 blank. I have written several lines of code into its function.php. however it is not working right now, here is what i wrote:

function bo_wrap_comment_text($content) {
    $content = get_comment_text();
    $texta = urlencode(get_comment_text());
    $textb = "http://www.google.com/search?btnI&q=" + $texta;
    return '<a href="'.$textb.'">'.$content.'</a>';
}
add_filter('wp_insert_comment','bo_wrap_comment_text',1000);

a separate code(this one works) is tested here: http://phpfiddle.org and the code is:

   <?php 
        $texta='i hate apple';
        $textb=urlencode($texta);
        $textc= "http://www.google.com/search?btnI&q=".$textb;
        echo '<a href="'.$textc.'">'.$texta.'</a>';
   ?>

the wordpress site is here. It is simply a static front page. the title you see there is the title of comment area. everything related with blog posts has been hidden using css. we have manually added links to several comments as prototyping. what we want is replace manual work with wordpress functions. I would really appreciate any help.

因此我们制作了一个wordpress网站,每次创建评论时都会自动添加评论链接。 我们使用的主题是html5空白。 我在其function.php中写了几行代码。 但它现在不能正常工作,这就是我写的: p>

  function bo_wrap_comment_text($ content){
 $ content = get_comment_text(); 
 $ texta = urlencode  (get_comment_text()); 
 $ textb =“http://www.google.com/search?btnI&q=”+ $ texta; 
 return'&lt; a href =“'。$ textb。'”  &GT;”。$内容。 '&LT; / A&GT;'; \ N} 
add_filter( 'wp_insert_comment', 'bo_wrap_comment_text',1000); 
 代码>  PRE> 
 
 

一 单独的代码(这个工作)在这里测试: http://phpfiddle.org ,代码是: p>

 &lt;?php 
 $ texta ='我讨厌苹果'; 
 $ textb = urlencode($ texta); 
 $ textc =“http://www.google。  com / search?btnI&amp; q =“。$ textb; 
 echo'&lt; a href =”'。$ textc。'“&gt;'。$ texta。'&lt; / a&gt;'; 
?&gt;  
  code>  pre> 
 
 

wordpress网站此处 。 它只是一个静态的首页。 您看到的标题是评论区域的标题。 与博客帖子相关的所有内容都已使用css隐藏。 我们手动添加了几个注释的链接作为原型。 我们想要的是用wordpress功能取代手工工作。 我真的很感激任何帮助。 p> div>

You need this hook instead to edit comment data:

http://codex.wordpress.org/Plugin_API/Filter_Reference/preprocess_comment