Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: How to get a blog post link from a comment link

@henrywright

Moderator

You need to get the comment ID from the URL and then you can look up the post. So imagine you have this:

https://example.com/2016/07/09/post-name/#comment-12

The comment ID is 12. You’d need to extract that from the string. Stuff like preg_replace() or filter_var() can be used here. Once you have the comment ID you can do this:

$comment = get_comment( $comment_id );
echo get_permalink( $comment->comment_post_ID );
Skip to toolbar