Our blog is in a subdirectory of the WebPage http://example.com/blog. Here is an example of a cancel reply link:

<a rel="nofollow" id="cancel-comment-reply-link" href="/postcategory/postname.html#respond"> style="display:none;">cancel reply</a></small>

As you can see, cancel reply links to domain.com/postcategory/postname.html#respond, which results in a 404 error.

How can I find a workaround without disabling comments?

I've already tried filtering in the functions.php, but that disabled the comment function somehow completely:

add_filter( 'cancel_comment_reply_link', '__return_false' );

Kind regards for your immediate help.

  • I don't think that this is the cause of your problem, but I think you shouldn't be using __return_false as filter function, as filters are expected to return strings. I think a better choice would be to use __return_empty_string as filter function.
    – JHoffmann
    Feb 9 '17 at 17:35
  • Hi, why don't you simply use CSS if you just want to disable reply link?
    – Jack Johansson
    Feb 9 '17 at 18:03
  • @Jack it is actually not displayed by css but, the wrong url is still parsed by google, giving me a hell lot of 404 sites in my system. Feb 10 '17 at 9:14

Try using this filter to fully modify the link and it's text:

apply_filters( 'cancel_comment_reply_link', $formatted_link, $link, $text );

You can modify the proper value depending on your needs. You might also be able to use a preg_replace() to modify the link and add your /blog/ value to it.

To remove the link entirely, use:

add_filter( 'cancel_comment_reply_link', '', '', '' );

  • cool, thanks...could you pls show me how? Feb 10 '17 at 6:51
  • You are welcome. I updated the answer. The code goes in your theme's functions.php.
    – Jack Johansson
    Feb 10 '17 at 7:14
  • Hey jack.. I will try, thanks... could you be so kind as to elaborate how to use the preg_replace() in the functions.php to simply add the domain.com/blog to the front of the correct rest of our url, which is there? Kind regards... (i am a noob in programming, pls excuse) Feb 10 '17 at 9:16
  • This way I would receive a correct link to a correct site instead of disabling the cancel link to a wrong site. - deleting the cancel link would result in a bad user experience, if the user clicks on one comment but decides to answer to an other, as both comment fields would still be open. Kind regards... Feb 10 '17 at 9:23

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.