Site icon Hip-Hop Website Design and Development

Pagination with WordPress default gallery?

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:

https://www.motorizm.net/bugatti-type-41-royale/

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?