comment_form example

    if ( isset( $attributes['textAlign'] ) ) {
        $classes[] = 'has-text-align-' . $attributes['textAlign'];
    }
    if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
        $classes[] = 'has-link-color';
    }
    $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );

    add_filter( 'comment_form_defaults', 'post_comments_form_block_form_defaults' );

    ob_start();
    comment_form( array()$block->context['postId'] );
    $form = ob_get_clean();

    remove_filter( 'comment_form_defaults', 'post_comments_form_block_form_defaults' );

    // We use the outermost wrapping `<div />` returned by `comment_form()`     // which is identified by its default classname `comment-respond` to inject     // our wrapper attributes. This way, it is guaranteed that all styling applied     // to the block is carried along when the comment form is moved to the location     // of the 'Reply' link that the user clicked by Core's `comment-reply.js` script.     $form = str_replace( 'class="comment-respond"', $wrapper_attributes$form );

    
<?php if ( comments_open() ) : ?> <!-- If comments are open, but there are no comments. --> <?php else : // Comments are closed. ?> <!-- If comments are closed. --> <p class="nocomments"><?php _e( 'Comments are closed.' ); ?></p> <?php endif; ?> <?php endif; ?> <?php comment_form(); ?>

            )
        );
        ?> <?php if ( ! comments_open() ) : ?> <p class="no-comments"><?php esc_html_e( 'Comments are closed.', 'twentytwentyone' ); ?></p> <?php endif; ?> <?php endif; ?> <?php     comment_form(
        array(
            'title_reply'        => esc_html__( 'Leave a comment', 'twentytwentyone' ),
            'title_reply_before' => '<h2 id="reply-title" class="comment-reply-title">',
            'title_reply_after'  => '</h2>',
        )
    );
    ?> </div><!-- #comments -->
Home | Imprint | This part of the site doesn't use cookies.