Skip to content

Instantly share code, notes, and snippets.

@ravismakwana
Created April 13, 2022 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravismakwana/0ccc7ca3fdc5f266018fd36a8e263922 to your computer and use it in GitHub Desktop.
Save ravismakwana/0ccc7ca3fdc5f266018fd36a8e263922 to your computer and use it in GitHub Desktop.
Post pagination with bootstrap 5
<?php
function bootstrap_pagination(){
$allowed_tags = [
'span' => [
'class' => []
],
'ul' =>[
'class' => [],
],
'li' =>[
'class' => [],
],
'a' => [
'class' => [],
'href' => [],
],
];
$args = [
'type' => 'array',
'prev_next' => true,
'prev_text' => __('« Prev'),
'next_text' => __('Next »'),
];
$pages = paginate_links($args);
if (is_array($pages)) {
$pagination = '<ul class="pagination justify-content-center">';
foreach ($pages as $page) {
$current_class = strpos($page, 'current') ? 'active' : '';
$pagination .= '<li class="page-item '.$current_class.'">' . str_replace('page-numbers', 'page-link', $page) . '</li>';
}
$pagination .= '</ul>';
}
printf('<nav class="asgard-pagination">%s</nav>', wp_kses($pagination, $allowed_tags));
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment