Test for if you're on 1st page of paginated post (with nextpage quicktag)

I'm developing a site that involves a lot of long posts I'd like to break up using the nextpage quicktag. On the first page there's a large splash photo in the header that I'd like to disappear on subsequent pages—so I need some way of testing if the user is on the first page. I did find this code:

if ( isset($wp_query-query_vars['page'] ) )

But that seems to only works with default permalink settings. I need something that works with the Postname permalink setting. Any help is greatly appreciated.

Topic nextpage pagination Wordpress

Category Web


I am not sure why your code doesn't work, but you should be able to check the page global. It should be a positive number on all but first page of a pages post. $page is NULL on the first page but set to an integer otherwise. The following should work, and does when I test it.

global $page;
if (empty ($page)) {
    echo 'first page';
}

... should work.


As suggested by @s_ha_dum, you can check the value of page. The value is 1 when you're on the first page.

global $page;
if ( $page == 1 ) :
    // you're on the first page
endif;

But probably you need to check if the post is paginated first:

global $multipage;
if ( 0 !== $multipage ) :

    global $page;
    if ( $page == 1 ) :
        // you're on the first page
    endif;

endif;

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.