Archived topic
Edit inc/structure/commenting.php on Child Theme
6 replies · Started by Rogi on June 3, 2021
I want to edit the inc/structure/commenting.php file.
Is there a way to do this in the Child Theme?
Thanks in advance.
Hi there,
I believe you meant "comments.php" which is this one? https://github.com/tomusborne/generatepress/blob/master/inc/structure/comments.php
It should be possible by copying it and creating a new file for it then added to the child theme.
Is there any specific thing you want to change? Perhaps we don't need a child theme template it as some parts can be filtered.
Let us know.
Hi Elvin!
First, thanks for the reply.
Exactly, the correct file name is comments.php and not commenting.php...
I made several changes to this file and I don't want to lose them if the theme is updated.
The changes I made were in <footer class="comment-meta">:
<footer class="comment-meta">
<?php
if ( 0 != $args['avatar_size'] ) { // phpcs:ignore
echo get_avatar( $comment, $args['avatar_size'] );
}
?>
<div class="comment-author-info">
<div <?php generate_do_element_classes( 'comment-author' ); ?>>
<?php printf( '<cite itemprop="name" class="fn">%s</cite>', get_comment_author_link() ); ?>
<div class="comment-date-bb">
<a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
<time datetime="<?php comment_time( 'c' ); ?>" itemprop="datePublished">
<?php
printf(
/* translators: 1: date, 2: time */
_x( ' | %1$s', '1: date, 2: time', 'generatepress' ), // phpcs:ignore
get_comment_date(), // phpcs:ignore
get_comment_time() // phpcs:ignore
);
?>
</time>
</a>
</div>
<div class="comment-edit-bb">
<?php edit_comment_link( __( 'Edit', 'generatepress' ), '<span class="edit-link">| ', '</span>' ); ?>
</div>
</div>
</div>
<?php if ( '0' == $comment->comment_approved ) : // phpcs:ignore ?>
<p class="comment-awaiting-moderation"><?php esc_html_e( 'Your comment is awaiting moderation.', 'generatepress' ); ?></p>
<?php endif; ?>
<div class="comment-link-bb">
<a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">Link</a>
</div>
</footer>
I will copy and create a file in the Child Theme as you suggested. Let's see if it works.
Thanks!
Elvin,
I created an inc/structure folder in the Child Theme and pasted the changed comments.php file there.
In the Parent Theme'sinc/structurefolder I placed the originalcomments.php file.
But Wordpress still loads only the Parent Theme inc/structure file, ignoring the same Child Theme file.
Hi Igor,
Unfortunately WordPress only allows the child theme to overwrite the top level file - this isn't something the theme can control.
Usually we have a filter for everything though. What are you trying to achieve?
Leo, thanks for clearing this up.
I'm changing a lot of things that can't be done using filters.
Thank you very much anyway.
No problem :)