is_paged()WP 1.5.0

Checks whether the pagination page is displayed (page type /page/2, /page/3). Conditional tag.

This function works only for archive pages such as categories, tags, author archives, main blog page, dates etc. I.e. works for those pages that can be divided into several.

This function does not apply to posts and ыефешс pages separated by the <!--nextpage--> tag. Read more at Pagination for WordPress post content.

No Hooks.

Return

true|false. Whether the query is for a paged result.

Usage

if( is_paged() ){
	// ...
}

Examples

0

#1 Remove something from the sidebar on the pagination pages

<?php if( !is_paged() ){ ?>

	<!-- A block that will only be shown on the main page, not the pagination page -->

<?php } ?>
0

#2 Check on what page of the pagination we are

When you need to check a specific pagination page, use get_query_var('paged').

if( get_query_var('paged') == 3 ){ 
	// Will work on the 3rd page of pagination
}
0

#3 Check whether posts are divided into pages

you can use the shortcode <!--nextpage--> in post content. This code will divide the text of the post into several pages. And, for example, the URL of the second page will look like this: http://example.com/privet-mir/2/.

Example 1

$paged = get_query_var( 'page' );
// $paged = $wp_query->get( 'page' ); // or we can do so...

if( $paged < 2 ){
	// This is the first page or post is not divided into pages
}
else {
	// That's 2,3,4 ... page of the divided post.
}

Example 2

Check if the post is divided into pages...

the_post();

if( !empty($GLOBALS['multipage']) ){
	// the post is divided into pages
}

Example 3

Let's find out how many pages the post has

the_post();

if( !empty($GLOBALS['numpages']) ){
	if( $GLOBALS['numpages'] === 1 ){
		// not devided
	}
	else {
		// the post is divided into pages
		echo "Number of pages {$GLOBALS['numpages']}";
	}
}

Notes

  • Global. WP_Query. $wp_query WordPress Query object.

Changelog

Since 1.5.0 Introduced.

is_paged() code WP 6.4.3

function is_paged() {
	global $wp_query;

	if ( ! isset( $wp_query ) ) {
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
		return false;
	}

	return $wp_query->is_paged();
}