I'm working on a site that has comments enabled, with no moderation. After commenting on a page, your comment shows up on that page, and I've added a Facebook share icon below each comment that allows you to share "website.com/page?comment=10" (or whatever your specific comment ID is). You could also potentially share someone else's comment if you wanted to.

I would now like to include a pop-up message after a user submits a comment, which says something like "Thanks for commenting! Would you like to share this comment on Facebook?" and then allows you to share that same URL (so that it points directly to your comment on the page).

I've tried to find teh API hooks for "after comment has been posted" in an attempt to program this myself, but I'm not really finding much. My plan was to add something to my child theme's functions.php file which adds a function to the "after comment has been posted" hook, which creates a pop up in JavaScript which is populated with the message and a Facebook share button, which is set to share the comment's specific URL (which it would have to receive from the comment form somehow). Is something like this the best way to go?

Does anyone have any advice on how to proceed?

1 Answer 1


Have you tried comment_post action? It's fired right after the comment is inserted into the database.

function share_comment_on_facebook( $comment_ID ) {
    $commentdata = get_comment( $comment_ID );

    if ( $commentdata['comment_approved'] ) {
        // fire up the code to launch pop up
add_action( 'comment_post', 'share_comment_on_facebook' );
  • This is certainly interesting, but the documentation is fairly sparse, even on the WordPress codex website. What I'm trying to do is add an action, and get the comment ID from that action, so that I can craft a Facebook share button which shares website.com/page?comment=[comment ID]. This function seems to take $comment_ID as a parameter...I'm not quite sure how to use it
    – Jake
    Oct 21, 2014 at 21:44
  • @user774359 Have a look at the updated code, once you have the $comment_ID, you can later use it fire up some javascript to open a pop up and do the needful. Oct 22, 2014 at 3:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.