I’m a layman trying to put a prewritten comment in the WordPress comment section by modifying comments.php:
<?php if ( comments_open() ) { comment_form(array(
'title_reply'=>'',
'label_submit' => esc_html__( 'Send!' ),
'comment_field' => esc_html__( 'Prewritten comment' ),
)); } ?>
The two first adjustments works fine… but what should the third one be to fullfil my wish?
]]>I propose an improvement to this great plugin. For better compatibility with all the themes, I recommend hooking to comment_form_fields
filter instead of comment_form_default_fields
which is used now.
From https://developer.www.ads-software.com/reference/functions/comment_form/ it is apparent that when the theme sets is own 'fields'
in the $args
the checkbox is not shown.
I can provide a PR if needed.
Let me know! Thank you.
]]>I am currently developing a wordpress theme and I have a problem with comments. In fact, I would like to add a comment form to a template I created. But when I add <?php comment_form(); ?> nothing is displayed in front-end.
However I inserted the same code in my front-page.php and the form is displayed very well.
I also tried with <?php comments_template(); ?> and it only displays the div#comments.
Can someone help me, please?
For info, I named my template music.php and placed it in the /page-templates folder.
Thank you.
]]>Thank you.
]]>comments.php File :
<?php
// Whether the current post is open for comments.
if (comments_open()) {
// Display comments
wp_list_comments( array(
'callback' => 'tuhfa_comments_template_calback'
) );
comment_form();
}else {
echo "Closed";
}
?>
Please Help Me.
]]>comments.php File :
<?php
// Whether the current post is open for comments.
if (comments_open()) {
// Display comments
wp_list_comments( array(
'callback' => 'tuhfa_comments_template_calback'
) );
comment_form();
}else {
echo "Closed";
}
?>
Please Help Me.
]]>There is this post about the difference between comments_template() and comment_form.
That makes sense, from a hierarchical standpoint I’m not sure though. I’m creating my own WP template but the default fields that the form return are good enough for me. So I don’t need to do any customization, I just use CSS to style the default one, suing its classes and JS to add the ones that I want to add. I tried using the following in my single.php:
// we display comments
$comments = get_comments(array(
// 'status' => 'approve',
));
$args = array(
'reverse_top_level' => false
);
wp_list_comments($args, $comments);
//we display the comments template
comment_form(); we use this as opposed to comments_template();
This works partially, the only problem is that, it will display all my comments in every single post page. Not the comments that belong to a particular post. Can anyone provide more insights in why this is happening? I feel that I’m missing something. And also, if one could expand more on comments_template() vs comment_form() it will be highly appreciated it.
Thanks!
]]>In the theme’s comment.php file, I’m modifying the $args parameter that will be passed to comment_form();
Specifically, I want to add text to comment_notes_before
. Thus my $arg looks like this
$comments_args = array('comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.' ) . ( $req ? $required_text : '' ) . 'See our privacy statement</p>');
This raises an “Undefined variable: required_text“
Of course I can hardcode the text, but that feels to me more like a hack. I guess this is really a php question. Is there something else I need to include in my code to expose the $required_text
variable? Or is it never accessible?
Or, is it possible to append to the default rather than replacing the default text?
Thank you.
]]>While I have searched for a reason for this, I haven’t been able to find a cause for it. The problem strangely only happens on our production server and seems to have appeared around the day 4.3 came out.
I tried to enforce comments to be open with the bare minimum, but it still returns false.
function my_comments_open( $open, $post_id ) {
//$post = get_post( $post_id );
$open = true;
return $open;
}
add_filter( 'comments_open', 'my_comments_open', 10, 2 );
The following code above still makes the value return as false.
I am really at a loss and this is the first time something like this happen.
Anyone got this problem or maybe knows what can be conflicting? I tried deactivating plugins, without success. Switching to a default Twenty theme works (the comment form shows), so it’s not an issue in the database or with plugins.
Seems like something replaces or changes the returned value. I tried commenting most of my functions.php, but without success… Someone has an idea at to what could cause this? Thanks!
]]>The relevant code is below:
<?php
$comments_args = array(
'label_submit' => __( 'Comment','adelle-theme' ),
'title_reply' => __( 'Leave a Reply','adelle-theme' ),
'title_reply_to' => __( 'Leave a reply to %s','adelle-theme' ),
'cancel_reply_link' => __( 'Cancel reply','adelle-theme' ),
'comment_notes_before' => '',
'comment_notes_after' => '',
'comment_field' => '<p><textarea name="comment" class="comment-textarea" title="' . __( 'Comment','adelle-theme' ) . '" cols="50" rows="5" tabindex="1"></textarea></p>',
'fields' => apply_filters( 'comment_form_default_fields', array(
'author' => '<p><input type="text" name="author" class="comment-input" title="'.__( 'Name','adelle-theme' ).'*" value="'.$comment_author.'" size="22" tabindex="2" />',
'email' => '<input type="text" name="email" class="comment-input" title="'.__( 'Email','adelle-theme' ).'*" value="'.$comment_author_email.'" size="22" tabindex="3" />',
'url' => '<input type="text" name="url" class="comment-input" title="'.__( 'Website','adelle-theme' ).'" value="'.$comment_author_url.'" size="22" tabindex="4" /></p>',
) ),
);
comment_form( $comments_args );
?>
https://www.ads-software.com/plugins/stop-spam-comments/
]]>