Out of the box, WordPress supports the ability to paginate individual posts.

For those who aren’t familiar, it means that you’re able to literally paginate your posts such that a post may consist of multiple pages (kind of a weird concept, huh?).

Paginated Posts

Some people may use this feature, some people may not; however, if you’re working on a theme, then you need to be prepared for this case and provide appropriate styling.

But the way if which you determine if a post is paginated or not can lead to a bit of cluttered code, so in order to keep the code as readable as possible (and to keep the logic separated from the template), here’s one way that you can check is a post is paginated.

The Post is Paginated?

WordPress has a global variable, `$multipage` that will denote whether or not a post is paginated or not.

In the case that a given post is not paginated, then `$multipage` will be equal to 0. This means that’s it’s really easy to write a function to encapsulate this logic and return `TRUE` if the post is paginated:

To display the links to each of the individual posts pages, you use the function `wp_link_pages` which is customizable (as seen in the linked Codex article).

Normally, I wrap this in some sort of container, and then I wrap the container in a conditional that allows me to conditionally display the container based on of the post is paginated.

In using the function above, it looks like this:

It’s a bit cleaner, right?

A Separation of Concerns

In its most basic form, this is a separation of concerns – logic specifically dealing with determining if a given post is paginated is located in its own function, and then the template file is able to call the function to determine whether or not to display a container for the list of pages.

Anyway, this is a relatively simple idea, but I’ve found it to come in handy in a couple of projects and thought it was worth sharing.

Next, you can then use this function in your templates to create a more readable conditional on whether or not to display the container for the post pagination links that will allow you to provide styling that only appears if those links appear.