• Hi All,

    I’m trying to clean up my single posts by only displaying the comments for a particular post when the user clicks on the “view comments” url. I’ve created a child theme and have my own custom code to display the post title, content, etc. and I’m inserting a link to the comments page using the comments_link() function.

    What I’m unclear on, and struggling with, is I think I need some kind of conditional statement in my single.php so that if the “/#comments” which is appended to the URL is there, then I display the comment template, and if its not, then I display a link to the comments URL.

    I’ve been trying to google this for quite a while, but I’m not having any luck.

    Is there some kind of flag or variable I can read to determine if the user has clicked on the comments URL? If I can figure that out, then a simple conditional statement to display or not display the comments is all I need, but I can’t figure out how to do this.

    Any help is appreciated. Thanks.

Viewing 1 replies (of 1 total)
  • Unfortunately, the hash (#comments) doesn’t get sent to the server – It’s client side only.

    Ony way around this would be to have the comments always loaded server side, but hidden on the client side using JS. Then just have a click listened on the link which will show the comments by showing the hidden div

Viewing 1 replies (of 1 total)
  • The topic ‘Only Display Comments When Viewing Comments URL’ is closed to new replies.