Here is the part of code handling pagination in functions.php:

// Pagination Setup
$current = (get_query_var('paged')) ? get_query_var( 'paged' ) : 1;
$per_page = 3;
$offset = ($current-1) * $per_page;
$big = 999999999;
$total = sizeof($attachments);
$total_pages = round($total/$per_page);
if( $total_pages < ( $total/$per_page ) ){
    $total_pages = $total_pages+1;

// Pagination output
$output .= paginate_links( array(
    'base' => str_replace($big,'%#%',esc_url(get_pagenum_link($big))),
    'format' => '?paged=%#%',
    'current' => $current,
    'total' => $total_pages,
    'prev_text'    => __('&laquo;'),
    'next_text'    => __('&raquo;')
) );

Here is the page:


The issue:

The code successfully divides images into groups by three, creates pages for these groups, creates pagination numbers and creates links to the pages. But when I click on any pagination link, I do not go anywhere.

Although when the page ( https://www.motorizm.net/bugatti-type-41-royale/ ) has "Status: Draft", pagination links do work as they are supposed to.

Any ideas?

1 Answer 1


Ended up like this. Made this changes and it worked:


'base' => str_replace($big,'%#%',esc_url(get_pagenum_link($big))),


'base' => get_permalink( $post->post_parent ) . '%_%',

And changed:

'format' => '?paged=%#%',


'format' => 'paged=%#%',

Then added a filter with rewrite tag and rule:

add_filter('init', 'post_gallery_add_rewrite_tag_rule_2022');
function post_gallery_add_rewrite_tag_rule_2022() {
    add_rewrite_rule('([^/]+)/paged=/?([0-9]{1,})/?$', 'index.php?name=$matches[1]&paged=$matches[2]', 'top');

Then (after uploading functions.php) in WordPress admin panel:

Settings -> Permalinks -> [ Save Changes ]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.