在Wordpress上提交评论后自定义“成功”消息

时间:2015-02-15 17:34:55

标签: wordpress-plugin wordpress-theming wordpress

我需要在Wordpress上成功发布评论时显示成功消息。这该怎么做?

2 个答案:

答案 0 :(得分:2)

请尝试https://wordpress.org/plugins/wp-ajaxify-comments。它将在Wordpress上成功发布评论显示成功消息

答案 1 :(得分:2)

没有Ajax或插件。添加到function.php:

add_action( 'set_comment_cookies', function( $comment, $user ) {
    setcookie( 'ta_comment_wait_approval', '1', 0, '/' );
}, 10, 2 );

add_action( 'init', function() {
    if( isset( $_COOKIE['ta_comment_wait_approval'] ) && $_COOKIE['ta_comment_wait_approval'] === '1' ) {
        setcookie( 'ta_comment_wait_approval', '0', 0, '/' );
        add_action( 'comment_form_before', function() {
            echo "<p id='wait_approval' style='padding-top: 40px;'><strong>Your comment has been sent successfully.</strong></p>";
        });
    }
});

add_filter( 'comment_post_redirect', function( $location, $comment ) {
    $location = get_permalink( $comment->comment_post_ID ) . '#wait_approval';
    return $location;
}, 10, 2 );