functions – Determine if, within a post, you are on page 2 or greater – WordPress documentation circular

Question

If you are trying to determine if a singular single.php post page is on a paged() page number then this will require a little more logic.

But if you are simply trying execute a function if a post is on an archive page one… then this should be pretty straight forward doing this…

<?=
// args
$args = [
  'post_type' => 'post',
  'posts_per_page' => 10,
  'paged' => get_query_var('paged') ? absint(get_query_var('paged')) : 1
]

// setup query
$query = new WP_Query($args);

This will detect what page your are on with above query…

<?php

// if above query page number is 1
if($query['paged'] === 1 ) {

  // do stuff

}

Hopefully makes sense. Let me know if not.

in progress 0
Matt 2 weeks 2022-01-05T20:09:45-05:00 0 Answer 0 views 0

Answer ( 1 )

    0
    2022-01-07T01:41:31-05:00

    In that case, then this might work for you:

    function insert_feat_image( $content ) {
        global $page, $multipage;
    
        if ( $multipage && $page <= 1 ) {
            // it's the 1st page, so run your code here.
        } // else, it's not paginated or not the 1st page
    
        return $content;
    }
    

Leave an answer

Browse
Browse