When someone posts a comment, I think it’d be cool if it went to the comment after editing it.
The file that needs editing would be
So, here’s my suggested code.
$location = (empty($_POST['redirect_to'])) ? $_SERVER["HTTP_REFERER"] : $_POST['redirect_to'];
$comment_ID = $wpdb->get_var("SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = '$comment_post_ID' AND comment_author = '$comment_author' AND comment_author_email = '$comment_author_email' AND comment_author_url = '$comment_author_url' AND comment_content = '$comment_content' ORDER BY comment_ID DESC");
$location = (empty($_POST['redirect_to'])) ? $_SERVER["HTTP_REFERER"] . '#comment-' . $comment_ID : $_POST['redirect_to'];
Can anyone think of any issues or drawbacks of doing this? I wouldn’t think it’d break anything ’cause if comment ID doesn’t exist (i.e. due to it not being in the theme or it being a different page), it still displays the intended page.
I’m using it on my dev blog and it seems to work fine. 🙂
- The topic ‘Scroll comment after posting it’ is closed to new replies.