Skip to content

Instantly share code, notes, and snippets.

@cjmosure
Last active June 12, 2019 10:11
Show Gist options
  • Save cjmosure/d542f5f5d468855cb52effab5e9e2c95 to your computer and use it in GitHub Desktop.
Save cjmosure/d542f5f5d468855cb52effab5e9e2c95 to your computer and use it in GitHub Desktop.
WP-PageNavi - Bootstrap 4
<?php
/**
* Clean up pagination
*/
add_filter( 'wp_pagenavi', __NAMESPACE__ . '\\gc_pagination', 10, 2 );
function gc_pagination($html) {
$out = '';
$out = str_replace('<div','',$html);
$out = str_replace('class=\'wp-pagenavi\'>','',$out);
$out = str_replace('<a','<li class="page-item"><a class="page-link"',$out);
$out = str_replace('</a>','</a></li>',$out);
$out = str_replace('<span class=\'current\'','<li class="page-item active"><span class="page-link current"',$out);
$out = str_replace('<span class=\'pages\'','<li class="page-item"><span class="page-link pages"',$out);
$out = str_replace('<span class=\'extend\'','<li class="page-item"><span class="page-link extend"',$out);
$out = str_replace('</span>','</span></li>',$out);
$out = str_replace('</div>','',$out);
return '<ul class="pagination">'.$out.'</ul>';
}
?>
@DebasishPanda
Copy link

Thank you for the code!

@nunesbeto
Copy link

Thanks!!!

@whoisandywhite
Copy link

Updated code to fix output bug with latest PageNavi release

function wiaw_pagenavi_to_bootstrap($html) {
    $out = '';
    $out = str_replace('<div','',$html);
    $out = str_replace('class=\'wp-pagenavi\' role=\'navigation\'>','',$out);
    $out = str_replace('<a','<li class="page-item"><a class="page-link"',$out);
    $out = str_replace('</a>','</a></li>',$out);
    $out = str_replace('<span aria-current=\'page\' class=\'current\'','<li aria-current="page" class="page-item active"><span class="page-link current"',$out);
    $out = str_replace('<span class=\'pages\'','<li class="page-item"><span class="page-link pages"',$out);
    $out = str_replace('<span class=\'extend\'','<li class="page-item"><span class="page-link extend"',$out);  
    $out = str_replace('</span>','</span></li>',$out);
    $out = str_replace('</div>','',$out);
    return '<ul class="pagination" role="navigation">'.$out.'</ul>';
}
add_filter( 'wp_pagenavi', 'wiaw_pagenavi_to_bootstrap', 10, 2 );

@soufianesabiri
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment