您应该能够执行以下操作:
add_filter( \'comment_post_redirect\', \'custom_comments_redirect\', 10, 2 );
function custom_comments_redirect( $location, $comment ) {
$comment_id = $comment->comment_ID;
$custom_url = \'https://example.com/thank-you/?comment=\' . $comment_id;
return $custom_url;
}
并在;“谢谢你”;第页,您可以获得如下评论信息:
// Make sure you sanitize the GET input
$comment_id = (int) filter_input( INPUT_GET, \'comment\', FILTER_SANITIZE_NUMBER_INT );
if ( ! empty( $comment_id ) ) {
// Fetch comment if the ID is not 0
$comment = get_comment( $comment_id );
if ( ! empty( $comment ) ) {
$comment_author = $comment->comment_author;
$comment_content = get_comment_excerpt( $comment_id );
echo sprintf( __( \'Hi %s. Thank you for your comment "%s"...\' ), $comment_author, $comment_content );
// Do your thing here...
}
}
评论摘录的默认长度为20个单词,但您也可以通过过滤器进行调整:
// Set the comments excerpt length (number of words)
add_filter( \'comment_excerpt_length\', \'custom_comments_excerpt_length\' );
function custom_comments_excerpt_length() {
return 8;
}