Link #comments anchor only to last page of paginated posts
<?php
// Link #comments anchor only to last page of paginated posts
// -----------------------------------------------------------------
function ccd_comments_link( $permalink, $post_id ) {
global $multipage, $numpages;
if ( $multipage ) {
$pfCommentURL = get_permalink();
$pfCommentLinkAnchor = '/#comments';
$pfCommentLink = $pfCommentURL.$numpages.$pfCommentLinkAnchor;
} else {
$pfCommentURL = get_permalink();
$pfCommentLinkAnchor = '#comments';
$pfCommentLink = $pfCommentURL.$pfCommentLinkAnchor;
}
return $pfCommentLink;
}
add_filter( 'get_comments_link', 'ccd_comments_link', 10, 2 );
?>
WordPress Snippet