ControlledChaos of Controlled Chaos Design
8/9/2016 - 6:44 PM

Link #comments anchor only to last page of paginated posts

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 );

?>

Link #comments anchor only to last page of paginated posts

WordPress Snippet