• Resolved Nic727

    (@nic727)


    Hi,

    I’m about to add a comment form on my website and I’m using this site https://developer.www.ads-software.com/themes/template-files-section/partial-and-miscellaneous-template-files/comment-template/ and https://developer.www.ads-software.com/reference/functions/comment_form/ but I’m having some questions regarding what can or can’t be done.

    Comments timestamp :

    1. Is it possible to make it unclickable?
    2. Can I change the format to something like “2 days ago” instead of “May 31st, 2021 at 13h43” or just show the date without the hours?

    Labels/Buttons

    1. Is it possible to put placeholder instead of using labels?
    2. Is it possible to change the position of the reply or edit button? I would like to have my edit button on the right side instead of next to the time/date.

    Finally, is it possible to remove the <span class=”says”>say :</span> without having the just hide it with CSS?

    I also have a problems where I can’t use this properly:

    comment_form(
    		array(
    			'logged_in_as'       => null,
    			'title_reply'        => esc_html_e( 'Laisser un commentaire', 'aurora' ),
    			'title_reply_before' => '<h5>',
    			'title_reply_after'  => '</h5>',
    			'class_submit'       => 'btn btn-dark',
    			'format'             => 'html5',
    			'label_submit'       => 'Publier le commentaire',
    		)
    	);

    https://i.postimg.cc/ZqJd484L/comment.png

    For whatever reason, if I decide to use _e(‘Publier le commentaire’) for the label_submit, it doesn’t work. I know that _e is used for translation. However, it doesn’t work for the submit label. The title reply part doesn’t seem to take the _before and _after h5. It just put the title_reply outside on it’s own…

    Thank you in advance.

    • This topic was modified 3 years, 6 months ago by Nic727.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Moderator t-p

    (@t-p)

    I recommend asking at your theme’s support so the theme’s developers and support community can help you with this.

    Thread Starter Nic727

    (@nic727)

    Hi,

    I’m developing my own theme and using the default comments form.

    Moderator t-p

    (@t-p)

    Since you are developing own theme, You may find this useful Theme Handbook: Theme Handbook

    Moderator bcworkz

    (@bcworkz)

    To manage comment display, you can pass various args to wp_list_comments() if that is the function you use on your comments template. You don’t have to use it, you could write your own list comments function. The args for wp_list_comments() include “walker” and “callback”, which can be used to mange comment output in any manner you like. You could extend Walker_Comment class and override any methods involved as needed.

    The comment_form() function has numerous hooks you can use to alter the form. Review its source code for calls to do_action() and apply_filters().

    When you apply a custom title, the before and after args are not used since you can include your HTML in your “title” arg.

    _e() echoes out translation, you need to use variants like __() that return values and not echo. It’s dumb luck esc_html_e() works. It happens to echo at the right time. You should use esc_html__() instead.

    If you are going to rely upon the WP polyglots community for translations, it’s customary that translatable labels be in English. If you are managing your own translations you can use the gettext system as you see fit.

    You don’t really need to use comment_form() at all. You can build your own form as long as the submitted data goes to the same place and the field names are the same. For that matter you could handle comment submission yourself as well. If your theme is intended for the WP repository, the theme review team may frown upon wandering too far afield with comment handling.

    Thread Starter Nic727

    (@nic727)

    @bcworkz Thank you. I think it would be easier for me to work live with someone else to show me what to do… However, I’m trying my best to understand all this complexity and I’m kind of stuck.

    I would like to take all the comment list and comment form code and modify it for my need, but I’m not sure to understand all the source code here https://developer.www.ads-software.com/reference/functions/comment_form/ and https://developer.www.ads-software.com/reference/functions/wp_list_comments/

    My problems :

    1. wp_comment_list()
    I just wanted to remove the “says” span which I found is useless. I now use a display:none, but I feel like it’s just loading useless thing on the page. Same for the href for the timestamp of the comment which I removed by adding a pointer-event:none, but the link is still loading…

    2. wp_comment_form()
    The whole form is weirdly made. I would like the inputs (name, email, website), to be inside a div. I saw a site who did it, but I can’t find anything on the developer website that can add a container around the input. Also, is it possible to remove the labels and put placeholder?

    3. Errors
    I saw that if you enter wrong email, it goes to a different WP error page. Is it possible to just style the area or add some AJAX instead?

    Where can I find the the default callback for the form and list, so I can just edit or remove the part I don’t want?

    • This reply was modified 3 years, 6 months ago by Nic727.
    • This reply was modified 3 years, 6 months ago by Nic727.
    Thread Starter Nic727

    (@nic727)

    Hi again, I found this https://core.trac.www.ads-software.com/browser/tags/5.7.2/src/wp-includes/comment-template.php

    However, I only found the code for the list in version 4.0.1. I don’t understand why it doesn’t show up in 5.7.2?

    Whatever, I copied the code I found in my functions.php under a new function name and I will remove and modify what need to be done.

    But for the form, the code is way too long, so I was thinking about using the field array and just add another div in “author” and the closing div in “url”, so I can wrap them all inside something else and modify how it looks from there. Is that what I should do?

    For AJAX, I guess it can work the same way by adding code into the fields area and show the error code there.

    Thank you in advance

    • This reply was modified 3 years, 6 months ago by Nic727.
    • This reply was modified 3 years, 6 months ago by Nic727.
    Moderator bcworkz

    (@bcworkz)

    Yes, this forum format is not ideal for some types of support or the way many people best receive assistance. There is also live chat help available through IRC. WordPress IRC Live Help

    For listing comments, there is no default callback per se, but if you provided one it’ll be used. It’s a way of overriding the start_el() method of class Walker_Comment without making a replacement walker. The default code used in lieu of a custom callback is basically Walker_Comment::html5_comment(). Note that the order of args passed is not identical. The args passed to a custom callback are ($comment, $args, $depth)

    You can alter the HTML used for form fields through the ‘comment_form_fields’ filter. You callback is passed an array of all field HTML. You may add, alter, and unset any fields you like. Just be sure to keep the same field name attributes. However, if what you want to alter in the form is outside of the individual fields, such as container divs, your options are more limited.

    The bad email error is simply the wp_die() page which kills the comment submission process. Opportunities for altering the die error page are limited. You can use the ‘wp_die_handler’ filter to define your own handler. The default handler is _default_wp_die_handler(). You can use its source code as a basis to define your own. Note that this handler function handles a large proportion of die errors, not just the bad email error. There are other handlers for Ajax and XMLRPC requests, for example, but typical GET and POST requests use the default.

    The code you found for v4.0.1 has been moved to Walker_Comment class in later versions. See the link above.

    Thread Starter Nic727

    (@nic727)

    Thank you very much. I kinda fixed everything. I will keep my display:hidden stuffs, just because I don’t want to break anything, but I edited some of the comment form via the custom array ‘author’ => ”, etc.

    Kinda work now.

    Thank you for your answer ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Comments template questions’ is closed to new replies.