Skip to content

Instantly share code, notes, and snippets.

@cameronjonesweb
Created September 21, 2022 08:46
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 cameronjonesweb/9d7b338bdf7a15ab622b5c27c24cec4c to your computer and use it in GitHub Desktop.
Save cameronjonesweb/9d7b338bdf7a15ab622b5c27c24cec4c to your computer and use it in GitHub Desktop.
Bootstrapify `the_posts_pagination()`
<?php
/**
* Update `the_posts_pagination()` markup for Bootstrap 4 styles
*
* Does this monstrosity work? Yes! Should you use it? Probably not.
*
* @param $markup string Original markup.
* @return string Updated markup.
*/
function cameronjonesweb_bootstrapify_posts_pagination( $markup ) {
$markup = str_replace( 'div class="nav-links"', 'ul class="pagination"', $markup );
$markup = str_replace( '<a', '<li class="page-item"><a', $markup );
$markup = str_replace( '</a></li>', '</a></li>', $markup );
$markup = str_replace( '<span', '<li class="page-item disabled"><a', $markup );
$markup = str_replace( '</span', '</a></span', $markup );
$markup = str_replace( 'page-numbers', 'page-link', $markup );
return $markup;
}
/* USAGE */
echo cameronjonesweb_bootstrapify_posts_pagination( get_the_posts_pagination( array( 'class' => '' ) ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment