Support » Fixing WordPress » Stripping html tags out of comment hover title

  • A client uses html tags in his post tags, and this (unfortunately) translates into the comment tag hover (on the index page where it says ‘1 comment’, ‘2 comments’ etc).

    I’ve tried removing the tags using strip_tags() but it doesn’t work. Am I looking in the right place – comment-template.php in the comments_popup_link() function. I altered the title hover text and it corresponds on the page, so I think I am.

    My question is, can it be stripped of the tags, or is the attribute_escape(get_the_title()) preventing me? I apply the strip_tags() after that incidentally.


Viewing 1 replies (of 1 total)
  • I am using the Search-Everything plugin which will add a span tag to a post’s title (for highlighting) when it finds a match. Unfortunately the span tag is included in the title attribute of the Comment link. For example, if I had searched for “post”:

    <a href="xxx" title="Comment on My <span class="hilite">Post</span>">

    However, the span tag is not included in the title attribute of the permalink from the post’s title:

    <a href="xxx" title="Permanent Link to My Post">

    I did some poking around in the code and found that the function that generates the comments link, comments_popup_link(), uses esc_attr(get_the_title()) to retrieve the post title, while the permalink from the post’s title uses the_title_attribute(). So, I modified the comments_popup_link() function to use the_title_attribute() instead of esc_attr(get_the_title()). Now I always get a clean title attribute in the comments link.

    I changed line 971 in comment-template.php (wp 2.8.3) from

    $title = esc_attr( get_the_title() );


    $title = the_title_attribute('echo=0');

    Rich, the the_title_attribute() function is more or less the same as esc_attr(strip_tags(get_the_title())), so you were on the right track. The changed line could just as well be

    $title = esc_attr(strip_tags(get_the_title()));

    I suggest that this is a bug and should be fixed in a future release. I am new to WordPress, so I want to get some feedback (like Reporting Bugs suggests) before I go telling the developers how I think it ought to be done.


Viewing 1 replies (of 1 total)
  • The topic ‘Stripping html tags out of comment hover title’ is closed to new replies.