• Hello, I’ve just started using the Code Snippets plugin.

    I’ve created 3x new snippets, all related to the WordPress comments form. They’re all active but they don’t appear to be achieving the desired effects.

    The code snippets I’ve used are copied from WPBeginner and other places. I’ll paste them here. Is there anything simple I’m doing wrong please?!?!

    Snippet #1 – Moves name and email fields above comments form text area

    function wpb_move_comment_field_to_bottom( $fields ) {
    $comment_field = $fields[‘comment’];
    unset( $fields[‘comment’] );
    $fields[‘comment’] = $comment_field;
    return $fields;
    }

    add_filter( ‘comment_form_fields’, ‘wpb_move_comment_field_to_bottom’);

    Snippet #2 – Changes text of comments form GDPR checkbox

    add_filter( ‘comment_form_default_fields’, ‘wc_comment_form_change_cookies’ );
    function wc_comment_form_change_cookies( $fields ) {
    $commenter = wp_get_current_commenter();

    $consent = empty( $commenter[‘comment_author_email’] ) ? ” : ‘ checked=”checked”‘;

    $fields[‘cookies’] = ‘<p class=”comment-form-cookies-consent”><input id=”wp-comment-cookies-consent” name=”wp-comment-cookies-consent” type=”checkbox” value=”yes”‘ . $consent . ‘ />’ .
    ‘<label for=”wp-comment-cookies-consent”>’.__(‘Save my name and email address in this browser for the next time I comment.’).'</label></p>’;
    return $fields;
    }

    Snippet #3 – Change ‘Post Comment’ button text

    $commenter = wp_get_current_commenter();
    $req = get_option( ‘require_name_email’ );
    $aria_req = ( $req ? ” aria-required=’true'” : ” );
    $fields = array(
    ‘author’ => ‘<p class=”comment-form-author”>’ . ‘<label for=”author”>’ . __( ‘Name’ ) . ‘</label> ‘ . ( $req ? ‘<span class=”required”>*</span>’ : ” ) .
    ‘<input id=”author” name=”author” type=”text” value=”‘ . esc_attr( $commenter[‘comment_author’] ) . ‘” size=”30″‘ . $aria_req . ‘ /></p>’,
    ’email’ => ‘<p class=”comment-form-email”><label for=”email”>’ . __( ‘Email’ ) . ‘</label> ‘ . ( $req ? ‘<span class=”required”>*</span>’ : ” ) .
    ‘<input id=”email” name=”email” type=”text” value=”‘ . esc_attr( $commenter[‘comment_author_email’] ) . ‘” size=”30″‘ . $aria_req . ‘ /></p>’,
    );
    $comments_args = array(
    ‘fields’ => $fields,
    ‘label_submit’ => ‘Submit My Comment’
    );
    comment_form($comments_args);

    The page I need help with: [log in to see the link]

The topic ‘New user – snippets not working?!’ is closed to new replies.