questions

Edit pagination function – wordpress

Rate this post

I need to edit the pagination function to remove ‘previous’ and ‘next’ words and to change the arrow.

I use this function in function.php

function pagination_bar($custom_query) {

    $total_pages = $custom_query->max_num_pages;
    $big = 999999999;

    if ($total_pages > 1){
        $current_page = max(1, get_query_var('paged'));

        echo paginate_links(array(
            'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
            'format' => '?paged=%#%',
            'current' => $current_page,
            'total' => $total_pages,
        ));
    }
}

And this tag in my category page

<div class="row">
   <div class="col-md-12">
       <div class="pagination">
            <?php pagination_bar( $loop ); ?>
       </div>
   </div>
</div>

 

โœ”๏ธSolution:

you can use the prev_next argument to disable them

function pagination_bar( $custom_query ) {

    $total_pages = $custom_query->max_num_pages;
    $big = 999999999;

    if ($total_pages > 1){
        $current_page = max(1, get_query_var('paged'));

        echo paginate_links(array(
            'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
            'format' => '?paged=%#%',
            'current' => $current_page,
            'total' => $total_pages,
            'prev_next'=> false,
        ));
    }
}

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

Leave a Reply

Your email address will not be published.

Back to top button