09/04/2016   Comments Off on Display something only on the last page of a paginated post

View all snippets

In a project of mine, I only wanted Jetpack’s Related Posts to display on the last page of a paginated post. There was no need for the reader to see related posts at the end of each segment if the reader hadn’t reached the last segment of the post. To make this happen, I found this useful code:

<?php /* Only show on the last page if post is paginated */
global $page; global $numpages; if( $page == $numpages ) :?>

   <?php // put whatever you want here ?>

<?php endif;?>