Skip to main content
deleted 4 characters in body
Source Link
Sally CJ
  • 39.9k
  • 2
  • 26
  • 48

I read that it doesn't work for posts using <!--nextpage-->

Yes, that's correctNot necessarily, andbut basically, if the current URL ends with /page/<number> as in https://example.com/page/2/ and https://example.com/category/foo/page/2/, then is_paged() would work, i.e. it returns true on page 2, 3, etc.

But for singular posts with a page break, i.e. the <!--nextpage--> tag, where the URL normally ends with /<number> as in https://example.com/hello-world/2/, then is_paged() would return a false.

However, you can use get_query_var( 'page' ) (or the global $page variable) to get the page number and then render the featured image only if the page number is 1 or < 2.

So for example, just replace the !is_paged() in your if with (int) get_query_var( 'page' ) < 2, and then that image would no longer appear on page 2, 3 and so on.

I read that it doesn't work for posts using <!--nextpage-->

Yes, that's correct, and basically, if the current URL ends with /page/<number> as in https://example.com/page/2/ and https://example.com/category/foo/page/2/, then is_paged() would work, i.e. it returns true on page 2, 3, etc.

But for singular posts with a page break, i.e. the <!--nextpage--> tag, where the URL normally ends with /<number> as in https://example.com/hello-world/2/, then is_paged() would return a false.

However, you can use get_query_var( 'page' ) (or the global $page variable) to get the page number and then render the featured image only if the page number is 1 or < 2.

So for example, just replace the !is_paged() in your if with (int) get_query_var( 'page' ) < 2, and then that image would no longer appear on page 2, 3 and so on.

I read that it doesn't work for posts using <!--nextpage-->

Not necessarily, but basically, if the current URL ends with /page/<number> as in https://example.com/page/2/ and https://example.com/category/foo/page/2/, then is_paged() would work, i.e. it returns true on page 2, 3, etc.

But for singular posts with a page break, i.e. the <!--nextpage--> tag, where the URL normally ends with /<number> as in https://example.com/hello-world/2/, then is_paged() would return a false.

However, you can use get_query_var( 'page' ) (or the global $page variable) to get the page number and then render the featured image only if the page number is 1 or < 2.

So for example, just replace the !is_paged() in your if with (int) get_query_var( 'page' ) < 2, and then that image would no longer appear on page 2, 3 and so on.

Source Link
Sally CJ
  • 39.9k
  • 2
  • 26
  • 48

I read that it doesn't work for posts using <!--nextpage-->

Yes, that's correct, and basically, if the current URL ends with /page/<number> as in https://example.com/page/2/ and https://example.com/category/foo/page/2/, then is_paged() would work, i.e. it returns true on page 2, 3, etc.

But for singular posts with a page break, i.e. the <!--nextpage--> tag, where the URL normally ends with /<number> as in https://example.com/hello-world/2/, then is_paged() would return a false.

However, you can use get_query_var( 'page' ) (or the global $page variable) to get the page number and then render the featured image only if the page number is 1 or < 2.

So for example, just replace the !is_paged() in your if with (int) get_query_var( 'page' ) < 2, and then that image would no longer appear on page 2, 3 and so on.