0

I want to render the WordPress posts pagination markup with my own HTML markup. My theme has a pagination markup with ul > li format. But the WordPress default pagination markup is different than my markup.

How can I apply my own HTML markup instead of the default pagination markup?

1
  • 1
    Depends on what you use to print the pagination. Show us the code.
    – Max Yudin
    Commented Aug 14, 2018 at 9:22

1 Answer 1

0

do you mean post archive pagination? The paginate_links() function accepts a type parameter, so if all you need is a ul > li format you could try out something like:

    // archive pagination
    global $wp_query;
    $big = 999999999; // need an unlikely integer

    echo paginate_links( [
        'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
        'format' => '?paged=%#%',
        'current' => max( 1, get_query_var('paged') ),
        'total' => $wp_query->max_num_pages,
        `type`  => 'list',
    ] );

If you need a completely custom markup, you could try setting type param to 'array' and then build whatever you need with a foreach loop.

docs: https://developer.wordpress.org/reference/functions/paginate_links/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.