Customizing the comments section


I plan on using this section for questions in regards to customizing the comments section. I will add more at a later time.

1. There is a time stamp in the comments. How can we just remove the time (at time) and keep the date in place?

2. Clicking to reply to a comment the comment box does not open right below the comment being replied to but instead opens on the bottom of the page.

Thanks!


Hey Paal

There is a filter call beans_comment_time_text_output so you can do as such:

add_filter( 'beans_comment_time_text_output', 'example_comment_date' );

function example_comment_date() {

 return get_comment_date();

}

It is often easy to find such filters as I explained in this reply.

Regarding the reply form, I added it to the feature requests and it should be improved in Beans next major version.

Thanks,


Hey thierry,

I have an idea it might help you, We can use the default wordpress comment reply JS. I'm using it on all of my themes even on bean child themes.

It doesn't open the reply form in a new tab.


Thank you Thierry.

ps Can you adjust the url of this thread to become "Customizing the comments section"? Thanks.


Some code I have been experimenting with.

/*---- Under post: comments section ----*/

// Modify: No comment yet, add your voice below! 
add_filter( 'beans_no_comment_text_output', 'modify_no_comments_text' );
function modify_no_comments_text() {
  return 'Changing no comments yet text ';
}

// Modify: "Add a Comment" text
add_filter( 'beans_comment_form_title_text_output', 'modify_add_comment' );
function modify_add_comment() {
  return 'Add your comment below.';
}

// Modify: "Comment *" text
add_filter( 'beans_comment_form_legend_text[_comment]_output', 'modify_comment' );
function modify_comment() {
  return 'Your comment below.';
}

// Modify: "Post Comment" button text
add_filter( 'beans_comment_form_submit_text_output', 'modify_post_comment_btn' );
function modify_post_comment_btn() {
  return 'Share your words';
}

Data markup id for posted comments:

  • beans_comments_list
  • — beans_comment
  • —— beans_comment_header
  • ——— beans_comment_avatar
  • ——— beans_moderator_badge
  • ——— beans_comment_title
  • ——— beans_comment_meta
  • —— beans_comment_body
  • —— beans_comment_links
// Modify "Moderator" text
add_filter( 'beans_moderator_text_output', 'modify_post_moderator_text' );
function modify_post_moderator_text() {
 return '  Web dude';
}
// The original code. Can be adjusted by switching the uk tags.
beans_replace_attribute( 'beans_moderator_badge', 'class', 'uk-badge uk-margin-small-left');
// Adding class names.
beans_add_attribute( 'beans_no_comment', 'class', 'comments-no-comment' );
// The following comment-reply-title already has a class associated with it. But I wanted to share it anyway as some of the data markup id's do have classes associated with them but most do not.
//beans_add_attribute( 'comment_reply_title', 'class', 'meta-reply-title' );
beans_add_attribute( 'beans_comment_form_legend[_comment]', 'class', 'comments-subtitle' );
beans_add_attribute( 'beans_comment_form_submit', 'class', 'comments-submit-btn' );

// Keep the date and remove the time stamp on comment replies
add_filter( 'beans_comment_time_text_output', 'use_only_comment_date' );
function use_only_comment_date() {
    return get_comment_date();
}

Hi! @thierry

What is the best location in which putting the code to customize comments? In other words, instead of putting this in the typical functions.php, where it could be more appropriate? What if I want to customize the comment fragment in a child theme? Thank you!


Hey Jeff

I will add a new thread for what the best practice is on adding code to other php files. How do call these into the functions file. As this thread is about customizing the comments section.

I also found a solution that works. Include the following code inside the functions.php file. ​

require_once( get_stylesheet_directory() . '/inc/widgets.php' );

Hi guys,

@jeffsoy, could you give more details about what you would like to customize in the comments, that way I can point you to the right direction on how to go about it?

For most part and since pretty much everything is done through actions, filters and Beans API, you can organize your code the way you like it by splitting them in php files and call it the way Paal mentioned in his last comment 🙂

Thanks,


  1. Clicking to reply to a comment the comment box does not open right below the comment being replied to but instead opens on the bottom of the page.

I'm still experiencing this issue in Beans 1.5.0. I can't for the life of me figure out what the problem is, every required id field is present I also got the comment-reply.js script enqueued, yet it still opens the form on the bottom of the page instead of moving the form to below the comment that I want to reply to.

Hope someone can help me with this issue!



I'm assigned to this. Starting to look at it now.


Write a reply

Login or register to write a reply, it's free!