CUSTOM ADDED JUMP TO END PAGNATION

function custom_full_pagination( $total_pages = null, $current_page = null, $base_url = null ) {
	if ( null === $total_pages ) {
		global $wp_query;
		$total_pages = $wp_query->max_num_pages;
	}

	if ( $total_pages <= 1 ) return '';

	if ( null === $current_page ) {
		$current_page = max( 1, get_query_var('paged') );
	}

	if ( null === $base_url ) {
		$base_url = get_pagenum_link(1);
	}

	$pagination = '';

    // Jump to First Page <<
    if ( $current_page > 1 ) {
        $pagination .= '<a class="page-numbers page-first" href="page/1/">&laquo;&laquo;</a>';
    }

    // Previous Page <
    if ( $current_page > 1 ) {
        $pagination .= '<a class="page-numbers page-prev" href="page/' . ($current_page - 1) . '/">&laquo;</a>';
    }

	// Mid-size page numbers (strip out dots, first page, last page)
	$links = paginate_links( array(
		'base'      => trailingslashit( $base_url ) . '%_%',
		'format'    => 'page/%#%/',
		'current'   => $current_page,
		'total'     => $total_pages,
		'mid_size'  => 3,
		'end_size'  => 0,
		'type'      => 'array',
		'prev_next' => false,
	) );

	if ( is_array( $links ) ) {
		foreach ( $links as $link ) {
			// Skip links that are dots or match first/last page numbers
			if ( strpos( $link, 'dots' ) !== false ) continue;

			// Extract page number from the link text (regex for inner number)
			if ( preg_match( '/>(\d+)</', $link, $matches ) ) {
				$page_num = intval( $matches[1] );
				if ( $page_num === $total_pages && $current_page < ($total_pages - 3) ) continue;
                if ( $page_num === 1 && $current_page > 3 ) continue;
			}

			$pagination .= $link;
		}
	}

	// Next Page >
	if ( $current_page < $total_pages ) {
		$pagination .= '<a class="page-next page-numbers" href="/page/' . $current_page . '/">&raquo;</a>';
	}

	// Jump to Last Page >>
	if ( $current_page < $total_pages ) {
		$pagination .= '<a class="page-last page-numbers" href="/page/' . $total_pages . '/">&raquo;&raquo;</a>';
	}

	return '<nav class="custom-pagination" role="navigation"><div class="nav-links">' . $pagination . '</div></nav>';
}

Comments