paginate_links()
function returns unordered list with class named “page-numbers”. How can I change this class?
EDIT
Currently, I am using the band-aid method below.
$return = paginate_links( $arg );
echo str_replace( "<ul class='page-numbers'>", '<ul class="pagination">', $return );
Is there any better way?
paginate_links()
doesn’t offer a parameter and there are no hooks – see source – available to change the class(es). Which means you can do it like you have done it or you create your own pagination function based onpaginate_links()
.I was also searching for the same solution to use it with bootstrap pagination links,
the below code is working 100% in my theme.
use the function to call in index.php e.g;
<?php bittersweet_pagination(); ?>
or any other file. I also overwrite some bootstrap styling it might help you.for this you need to use type parameter
Another option not noted here is to copy the styles over to the WordPress pagination classes, instead of changing the class assigned to the element.
If you are using Bootstrap and bundling everything with sass, then you can apply the styles easily using the
@extend
directive.This may be pertinent to some situations, but I feel the code in the original question is the best solution for most applications.
If you want to just string replace your way to the bootstrap promised land then heres something that may help you.