• Hello everybody! Hello @alexmoise,

    In wordpress, using Divi theme, i try to reorganize in a compact way my comment template… wihtout any success. I try the comments.php, the comment-template.php and a lot of others php files without success.

    Goal: align on the same line, for the comment aera, the name (comment-form-author), the url and the email. To save space.

    Source for help:
    https://www.ads-software.com/support/topic/change-comments-form/
    https://divi.space/css-and-jquery/how-to-edit-the-divi-comments-section-without-a-plugin/

    And try to adapt this code from Alex, but can’t find a way to display them in a table with 3 columns.

    // comment form fields re-defined:
    add_filter( 'comment_form_default_fields', 'mo_comment_fields_custom_html' );
    function mo_comment_fields_custom_html( $fields ) {
    	// first unset the existing fields:
    	unset( $fields['comment'] );
    	unset( $fields['author'] );
    	unset( $fields['email'] );
    	unset( $fields['url'] );
    	// then re-define them as needed:
    	$fields = [
    		'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( 'A CUSTOM COMMENT LABEL', 'noun', 'textdomain' ) . '</label> ' .
    			'<textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" aria-required="true" required="required"></textarea></p>',
    		'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'A CUSTOM NAME LABEL', 'textdomain'  ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
    			'<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" maxlength="245"' . $aria_req . $html_req . ' /></p>',
    		'email'  => '<p class="comment-form-email"><label for="email">' . __( 'A CUSTOM EMAIL LABEL', 'textdomain'  ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
    			'<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30" maxlength="100" aria-describedby="email-notes"' . $aria_req . $html_req  . ' /></p>',
    		'url'    => '<p class="comment-form-url"><label for="url">' . __( 'A CUSTOM WEBSITE LABEL', 'textdomain'  ) . '</label> ' .
    			'<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" maxlength="200" /></p>',
    	];
    	// done customizing, now return the fields:
    	return $fields;
    }
    // remove default comment form so it won't appear twice
    add_filter( 'comment_form_defaults', 'mo_remove_default_comment_field', 10, 1 ); 
    function mo_remove_default_comment_field( $defaults ) { if ( isset( $defaults[ 'comment_field' ] ) ) { $defaults[ 'comment_field' ] = ''; } return $defaults; }

    In advance, thanks a lot for your help!!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @bdorat, the result of that code depends on the theme CSS,
    Could you post the URL where are you trying to put these 3 fields on one line? I can have a look and maybe I can come up with a CSS snippet to achieve your goal on your particular page ??
    Have a wonderful day!
    Alex.

    Hi @alexmoise I am also using this excellent code you provided on another thread. That topic is closed, so I am adding to this one, which is wrong but still related so hopefully I don’t get in trouble!

    So, at the bottom of this code is a function to remove the default comment field so it won’t appear twice. Unfortunately the result of this is that, while people not logged in will see my form as I want it to be seen, people already logged in see no comment area to fill in.

    How can I set that last bit to only suppress the default if someone is *not* logged in?

    Thanks!

    • This reply was modified 4 years, 2 months ago by janew.

    Hi @janew , that could be easily done by adding an IF in the mo_remove_default_comment_field() function, checking for is_user_logged_in() condition or something similar.

    If you need help with that please open a new topic and mention me there and I’ll have a closer look – just to avoid any trouble we both could get in by “hijacking” an old topic ??

    Best regards,
    Alex.

    • This reply was modified 4 years, 2 months ago by Alex Moise.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Change “Comments” form (bis)’ is closed to new replies.