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

问题描述 投票:2回答:2

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

wordpress-plugin wordpress-theming wordpress
2个回答
2
投票

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


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 );
© www.soinside.com 2019 - 2024. All rights reserved.