I'm using Drupal 7. When I post a comment to an article, its title looks like <a class="permalink" rel="bookmark" href="/comment/9#comment-9">comment title</a>.

I need only the “comment title” to be displayed, without the link.

I found the code in the comment.tpl.php template where the title of the comment is printing.

  <?php print render($title_prefix); ?>
  <h2<?php print $title_attributes; >><b><?php print $title></b></h2>

  <?php print render($title_suffix); ?>

As is said in the file description, $title already contains the link, so I can’t change it!

$title: Linked title

Does anybody know if there is a way to print the comment's title without a link?


Instead of

<?php print $title; ?>

You can do:

<?php print check_plain($comment->subject); ?>
| improve this answer | |
  • that works greate! after check_plain only the "comment title" left! – user16551 Apr 11 '13 at 14:02
  • @user16551 $comment->subject doesn't actually have any HTML code. check_plain only encodes special characters into HTML entities. – Beebee Apr 11 '13 at 14:38
  • The reason for using check_plain is to ensure that any 'special' characters in the subject line are encoded correctly for HTML. – Alfred Armstrong Apr 11 '13 at 14:43

Easiest way is to paste this code in template.php of your current theme, replace the word THEMENAME with the name of your theme (lowercase of course) and flush your cache:

 * Preprocess theme_comment()
function THEMENAME_preprocess_comment(&$variables) {
  // Remove all HTML tags from the title
  $variables['title'] = strip_tags($variables['title']);
| improve this answer | |
  • thank you! it warks! don't know why i didn't get it at once)) you can make it even easier, in comment.tpl.php instead of "print $title" just use "print strip_tags($title)" – user16551 Apr 11 '13 at 14:25
  • 1
    It's best to use theme preprocessors, so if your edited comment.tpl.php is overridden by another template file/module this change is preserved. – Beebee Apr 11 '13 at 14:27
  • 1
    +1 for using preprocessors! Even though template files do the job, preprocessors work best. – AyeshK Apr 11 '13 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.