I’ve got two routes to go here. Either I add a big bulky query to overwrite the paginate_links output or I add in the css to match the Bootstrap pagination component. I usually just custom style the standard output without regarding to the Bootstrap component. I’ve included both methods for now until I decide which is more efficient and customizable.
function bootstrap_pagination( \WP_Query $wp_query = null, $echo = true, $params = [] ) {
if ( null === $wp_query ) {
global $wp_query;
}
$add_args = [];
$pages = paginate_links( array_merge( [
'base' => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var( 'paged' ) ),
'total' => $wp_query->max_num_pages,
'type' => 'array',
'show_all' => false,
'end_size' => 3,
'mid_size' => 1,
'prev_next' => true,
'prev_text' => __( '« Prev' ),
'next_text' => __( 'Next »' ),
'add_args' => $add_args,
'add_fragment' => ''
], $params )
);
if ( is_array( $pages ) ) {
$pagination = '<div class="pagination"><ul class="pagination">';
foreach ( $pages as $page ) {
$pagination .= '<li class="page-item' . (strpos($page, 'current') !== false ? ' active' : '') . '"> ' . str_replace('page-numbers', 'page-link', $page) . '</li>';
}
$pagination .= '</ul></div>';
if ( $echo ) {
echo $pagination;
} else {
return $pagination;
}
}
return null;
}
https://gist.github.com/mtx-z/f95af6cc6fb562eb1a1540ca715ed928
- Bootstrap Pagination Component – https://getbootstrap.com/docs/5.0/components/pagination/
- the_posts_pagination – https://developer.wordpress.org/reference/functions/the_posts_pagination/
- paginate_links – https://developer.wordpress.org/reference/functions/paginate_links/
- stack overflow – https://wordpress.stackexchange.com/questions/247219/change-class-page-numbers-in-pagination
- stack overflow – https://wordpress.stackexchange.com/questions/126080/changing-pagination-list-class