How do you turn on comments for only the last page of a paginated post?

I have a single post with page breaks, but I only want to show comments and the ability to comment on the last page. Is this possible with WordPress?

Related posts

1 comment

  1. The easiest thing to do is to wrap the code that displays the comments in a conditional like this:

    if ($page === $numpages) {
      echo 'last page'; // this is the last of the <!--nextpage--> pages
    }
    

    That requires a theme edit, so it is only a good solution if this is a theme you’ve constructed and maintain.

    The variables (global) $page and $numpages are set by setup_postdata() and so should be reliable inside any properly constructed Loop.

Comments are closed.