How to replace 'reply' link with button? I want to replace the 'reply' link with button. As an intermediate solution I styled the link as a button with CSS, but I want it to be a real html 'button' element. The reason is, I do not want the reply links being visible to search engines, instead of it, I want to handle clicks on buttons with javascript.

I only found this 10 year old discussion on drupal site:  https://www.drupal.org/node/33170.

I created a custom comment.tpl.php and tried to modify the $links['comment']['#links']['comment-reply'] array, but without success.
There are two methods below. Both are equally effective except the second one requires that the &lt;button&gt; element be taken out of the list of links and put elsewhere in the template. This is either annoying or awesome depending on what outcome you're going for.
Method 1: Override MYTHEME_links()
In Drupal 7, you can turn the comment &quot;Reply&quot; link into a &lt;button&gt; element by overriding core's theme_links() function. It isn't pretty, but it's effective.
Add the function below to your theme's template.php file (replace &quot;MYTHEME&quot; with your theme name). Clear your cache for the change to take effect.

function MYTHEME_links($variables) {
  $links = $variables ['links'];
  $attributes = $variables ['attributes'];
  $heading = $variables ['heading'];
  global $language_url;
  $output = '';

  if (count($links) &gt; 0) {
    // Treat the heading first if it is present to prepend it to the
    // list of links.
    if (!empty($heading)) {
      if (is_string($heading)) {
        // Prepare the array that will be used when the passed heading
        // is a string.
        $heading = array(
          'text' =&gt; $heading,
          // Set the default level of the heading.
          'level' =&gt; 'h2',
        );
      }
      $output .= '&lt;' . $heading ['level'];
      if (!empty($heading ['class'])) {
        $output .= drupal_attributes(array('class' =&gt; $heading ['class']));
      }
      $output .= '&gt;' . check_plain($heading ['text']) . '&lt;/' . $heading ['level'] . '&gt;';
    }

    $output .= '&lt;ul' . drupal_attributes($attributes) . '&gt;';

    $num_links = count($links);
    $i = 1;

    foreach ($links as $key =&gt; $link) {
      $class = array($key);

      // Add first, last and active classes to the list of links to help out themers.
      if ($i == 1) {
        $class [] = 'first';
      }
      if ($i == $num_links) {
        $class [] = 'last';
      }
      if (isset($link ['href']) &amp;&amp; ($link ['href'] == $_GET ['q'] || ($link ['href'] == '&lt;front&gt;' &amp;&amp; drupal_is_front_page()))
         &amp;&amp; (empty($link ['language']) || $link ['language']-&gt;language == $language_url-&gt;language)) {
        $class [] = 'active';
      }
      $output .= '&lt;li' . drupal_attributes(array('class' =&gt; $class)) . '&gt;';

      if (isset($link ['href'])) {
        if ($key == 'comment-reply') {
          // Special handling for comment 'Reply' link.
          $output .= '&lt;button type=&quot;button&quot;&gt;' . $link ['title'] . '&lt;/button&gt;';
        }
        else {
          // Pass in $link as $options, they share the same keys.
          $output .= l($link ['title'], $link ['href'], $link);
        }
      }
      
      elseif (!empty($link ['title'])) {
        // Some links are actually not links, but we wrap these in &lt;span&gt; for adding title and class attributes.
        if (empty($link ['html'])) {
          $link ['title'] = check_plain($link ['title']);
        }
        $span_attributes = '';
        if (isset($link ['attributes'])) {
          $span_attributes = drupal_attributes($link ['attributes']);
        }
        $output .= '&lt;span' . $span_attributes . '&gt;' . $link ['title'] . '&lt;/span&gt;';
      }
      
      $i++;
      $output .= &quot;&lt;/li&gt;\n&quot;;
    }

    $output .= '&lt;/ul&gt;';
  }

  return $output;
}

Breaking it down...
This bit of code:
      if (isset($link ['href'])) {
        // Pass in $link as $options, they share the same keys.
        $output .= l($link ['title'], $link ['href'], $link);
      }

was changed to
      if (isset($link ['href'])) {
        if ($key == 'comment-reply') {
          // Special handling for comment 'Reply' link.
          $output .= '&lt;button type=&quot;button&quot;&gt;' . $link ['title'] . '&lt;/button&gt;';
        }
        else {
          // Pass in $link as $options, they share the same keys.
          $output .= l($link ['title'], $link ['href'], $link);
        }
      }

Of course you'll need to customize the output with whatever you need, whether it be a &lt;form&gt; wrapper or onclick attribute.
Unfortunately we can't use theme('button'...) because that would give us an input element. Of course we could change that by overriding theme_button() but that would affect all input elements on the site, and you would still need to override theme_links() in order to call it.
Method 2: MYTHEME_preprocess_comment()
If you don't mind taking &quot;Reply&quot; out of the links list altogether, this method will also work. It uses the comment preprocessor to unset the link, but not before taking the value of the URL and stuffing it into a new variable.
Again, add the function below to your theme's template.php file (replace &quot;MYTHEME&quot; with your theme name).
function MYTHEME_preprocess_comment(&amp;$variables) {
  if (isset($variables['content']['links']['comment']['#links']['comment-reply'])) {
    $variables['reply_url'] = $variables['content']['links']['comment']['#links']['comment-reply']['href'];
    unset($variables['content']['links']['comment']['#links']['comment-reply']);
  }
}

Then add this (or a variation of it) wherever you would like it to appear in your copy of comment.tpl.php:
&lt;?php if (isset($reply_url)): ?&gt;
&lt;button onclick=&quot;window.location.href='&lt;?php print $reply_url ?&gt;'&quot;&gt;Reply&lt;/button&gt;
&lt;?php endif; ?&gt;

Clear your cache for the change to take effect.