I have modified the comments.php file of the theme, but I’m told the is_paged is returning false when the comments are actually paginated.
Here is the code:
<?php
/**
* The template for displaying comments.
*
* This is the template that displays the area of the page that contains both the current comments
* and the comment form.
*
* @package HelloElementor
*/
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly.
}
if (!post_type_supports(get_post_type(), 'comments')) {
return;
}
if (!have_comments() && !comments_open()) {
return;
}
// Comment Reply Script.
if (comments_open() && get_option('thread_comments')) {
wp_enqueue_script('comment-reply');
}
// Check if we're on a paginated comments page
$is_comments_paged = (get_query_var('cpage') > 1);
?>
<section id="comments" class="comments-area">
<?php
comment_form(
[
'id_form' => 'commentform',
'comment_field' => '<p class="comment-form-comment"><label for="comment">' . __('Join the discussion', 'text-domain') . '</label><textarea id="comment" name="comment" cols="45" rows="5" style="height: 100px;" placeholder="' . __('Type Here...', 'text-domain') . '" aria-required="true"></textarea></p>',
'fields' => [
'author' => '<p class="comment-form-author"><label for="author">' . __('Display Name', 'text-domain') . '</label> ' .
($req ? '<span class="required">*</span>' : '') .
'<input id="author" name="author" type="text" value="' . esc_attr($commenter['comment_author']) . '" size="30" placeholder="' . __('Display Name', 'text-domain') . '"' . $aria_req . ' /></p>',
'email' => '<p class="comment-form-email"><label for="email">' . __('Email Address (Not Shown Publicly)', 'text-domain') . '</label> ' .
($req ? '<span class="required">*</span>' : '') .
'<input id="email" name="email" type="email" value="' . esc_attr($commenter['comment_author_email']) . '" size="30" placeholder="' . __('Email (Not Shown Publicly)', 'text-domain') . '"' . $aria_req . ' /></p>',
],
]
);
if (have_comments()) : ?>
<h3 class="title-comments">
<?php
$comments_number = get_comments_number();
if ('1' === $comments_number) {
printf(esc_html_x('One Comment', 'comments title', 'hello-elementor'));
} else {
printf(
esc_html(_nx(
'%1$s Comment',
'%1$s Comments',
$comments_number,
'comments title',
'hello-elementor'
)),
esc_html(number_format_i18n($comments_number))
);
}
?>
</h3>
<ol class="comment-list">
<?php
wp_list_comments(
[
'style' => 'ol',
'short_ping' => true,
'avatar_size' => 42,
]
);
?>
</ol><!-- .comment-list -->
<?php
ob_start(); // Start output buffering.
paginate_comments_links(['prev_text' => '‹ BACK', 'next_text' => 'MORE ›']);
$pagination = ob_get_clean(); // Get output and stop buffering.
echo str_replace('<a', '<a rel="nofollow"', $pagination); // Add rel="nofollow" to the links.
?>
<?php endif; // Check for have_comments(). ?>
</section><!-- .comments-area -->
Here is the page:
https://www.symetriarecovery.com/blog/what-is-suboxone-how-does-it-work/
Any thoughts?
I saw another post on here where the solution was that a condition wasn’t closed. But, I do not see that as a problem here.
I tried setting the is_paged in this comments.php, but I couldn’t get anything to work.
I checked with ChatGPT code interpreter.
I took out the no follow code part.
When fixed, RankMath should automatically change the pagnated pages to noindex. I know this is something I can do editing the funtions.php file, but I’d like it to work properly instead.