Title: paginate_links
Published: April 25, 2014
Last modified: May 20, 2026

---

# paginate_links( string|array $args = '' ): string|string[]|null

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/paginate_links/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/paginate_links/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/paginate_links/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/paginate_links/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/paginate_links/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/paginate_links/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/paginate_links/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/paginate_links/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/paginate_links/?output_format=md#wp--skip-link--target)

Retrieves paginated links for archive post pages.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/paginate_links/?output_format=md#description)󠁿

Technically, the function can be used to create paginated link list for any area.
The ‘base’ argument is used to reference the url, which will be used to create the
paginated links. The ‘format’ argument is then used for replacing the page number.
It is however, most likely and by default, to be used on the archive post pages.

The ‘type’ argument controls format of the returned value. The default is ‘plain’,
which is just a string with the links separated by a newline character. The other
possible values are either ‘array’ or ‘list’. The ‘array’ value will return an array
of the paginated link list to offer full control of display. The ‘list’ value will
place all of the paginated links in an unordered HTML list.

The ‘total’ argument is the total amount of pages and is an integer. The ‘current’
argument is the current page number and is also an integer.

An example of the ‘base’ argument is “[http://example.com/all_posts.php%_](http://example.com/all_posts.php%_)%”
and the ‘%_%’ is required. The ‘%_%’ will be replaced by the contents of in the ‘
format’ argument. An example for the ‘format’ argument is “?page=%#%” and the ‘%#%’
is also required. The ‘%#%’ will be replaced with the page number.

You can include the previous and next links in the list by setting the ‘prev_next’
argument to true, which it is by default. You can set the previous text, by using
the ‘prev_text’ argument. You can set the next text by setting the ‘next_text’ argument.

If the ‘show_all’ argument is set to true, then it will show all of the pages instead
of a short list of the pages near the current page. By default, the ‘show_all’ is
set to false and controlled by the ‘end_size’ and ‘mid_size’ arguments. The ‘end_size’
argument is how many numbers on either the start and the end list edges, by default
is 1. The ‘mid_size’ argument is how many numbers to either side of current page,
but not including current page.

It is possible to add query vars to the link by using the ‘add_args’ argument and
see [add_query_arg()](https://developer.wordpress.org/reference/functions/add_query_arg/)
for more information.

The ‘before_page_number’ and ‘after_page_number’ arguments allow users to augment
the links themselves. Typically this might be to add context to the numbered links
so that screen reader users understand what the links are for.
The text strings 
are added before and after the page number – within the anchor tag.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/paginate_links/?output_format=md#parameters)󠁿

 `$args`string|arrayoptional

Array or string of arguments for generating paginated links for archives.

 * `base` string
 * Base of the paginated url.
 * `format` string
 * Format for the pagination structure.
 * `total` int
 * The total amount of pages. Default is the value [WP_Query](https://developer.wordpress.org/reference/classes/wp_query/)‘
   s `max_num_pages` or 1.
 * `current` int
 * The current page number. Default is `'paged'` query var or 1.
 * `aria_current` string
 * The value for the aria-current attribute. Possible values are `'page'`, `'step'`,`'
   location'`, `'date'`, `'time'`, `'true'`, `'false'`. Default is `'page'`.
 * `show_all` bool
 * Whether to show all pages. Default false.
 * `end_size` int
 * How many numbers on either the start and the end list edges.
    Default 1.
 * `mid_size` int
 * How many numbers to either side of the current pages. Default 2.
 * `prev_next` bool
 * Whether to include the previous and next links in the list. Default true.
 * `prev_text` string
 * The previous page text. Default ‘« Previous’.
 * `next_text` string
 * The next page text. Default ‘Next »’.
 * `type` string
 * Controls format of the returned value. Possible values are `'plain'`, `'array'`
   and `'list'`. Default is `'plain'`.
 * `add_args` array
 * An array of query args to add. Default false.
 * `add_fragment` string
 * A string to append to each link.
 * `before_page_number` string
 * A string to appear before the page number.
 * `after_page_number` string
 * A string to append after the page number.

Default:`''`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/paginate_links/?output_format=md#return)󠁿

 string|string[]|null String of page links or array of page links, depending on `'
type'` argument.
 Null if total number of pages is less than 2.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/paginate_links/?output_format=md#source)󠁿

    ```php
    function paginate_links( $args = '' ) {
    	global $wp_query, $wp_rewrite;

    	// Setting up default values based on the current URL.
    	$pagenum_link = html_entity_decode( get_pagenum_link() );
    	$url_parts    = explode( '?', $pagenum_link );

    	// Get max pages and current page out of the current query, if available.
    	$total   = $wp_query->max_num_pages ?? 1;
    	$current = get_query_var( 'paged' ) ? (int) get_query_var( 'paged' ) : 1;

    	/*
    	 * Ensures sites not using trailing slashes get links in the form
    	 * `/page/2` rather than `/page/2/`. On these sites, linking to the
    	 * URL with a trailing slash will result in a 301 redirect from the
    	 * incorrect URL to the correctly formatted one. This presents an
    	 * unnecessary performance hit.
    	 */
    	if ( $wp_rewrite->using_permalinks() && ! $wp_rewrite->use_trailing_slashes ) {
    		$pagenum_link = untrailingslashit( $url_parts[0] );
    	} else {
    		$pagenum_link = trailingslashit( $url_parts[0] );
    	}
    	$pagenum_link .= '%_%';

    	// URL base depends on permalink settings.
    	$format  = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
    	$format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%';
    	if ( $wp_rewrite->using_permalinks() && ! $wp_rewrite->use_trailing_slashes ) {
    		$format = '/' . ltrim( $format, '/' );
    	}

    	$defaults = array(
    		'base'               => $pagenum_link, // http://example.com/all_posts.php%_% : %_% is replaced by format (below).
    		'format'             => $format, // ?page=%#% : %#% is replaced by the page number.
    		'total'              => $total,
    		'current'            => $current,
    		'aria_current'       => 'page',
    		'show_all'           => false,
    		'prev_next'          => true,
    		'prev_text'          => __( '&laquo; Previous' ),
    		'next_text'          => __( 'Next &raquo;' ),
    		'end_size'           => 1,
    		'mid_size'           => 2,
    		'type'               => 'plain',
    		'add_args'           => array(), // Array of query args to add.
    		'add_fragment'       => '',
    		'before_page_number' => '',
    		'after_page_number'  => '',
    	);

    	$args = wp_parse_args( $args, $defaults );

    	if ( ! is_array( $args['add_args'] ) ) {
    		$args['add_args'] = array();
    	}

    	// Merge additional query vars found in the original URL into 'add_args' array.
    	if ( isset( $url_parts[1] ) ) {
    		// Find the format argument.
    		$format       = explode( '?', str_replace( '%_%', $args['format'], $args['base'] ) );
    		$format_query = $format[1] ?? '';
    		wp_parse_str( $format_query, $format_args );

    		// Find the query args of the requested URL.
    		wp_parse_str( $url_parts[1], $url_query_args );

    		// Remove the format argument from the array of query arguments, to avoid overwriting custom format.
    		foreach ( $format_args as $format_arg => $format_arg_value ) {
    			unset( $url_query_args[ $format_arg ] );
    		}

    		$args['add_args'] = array_merge( $args['add_args'], urlencode_deep( $url_query_args ) );
    	}

    	// Who knows what else people pass in $args.
    	$total = (int) $args['total'];
    	if ( $total < 2 ) {
    		return null;
    	}
    	$current  = (int) $args['current'];
    	$end_size = (int) $args['end_size']; // Out of bounds? Make it the default.
    	if ( $end_size < 1 ) {
    		$end_size = 1;
    	}
    	$mid_size = (int) $args['mid_size'];
    	if ( $mid_size < 0 ) {
    		$mid_size = 2;
    	}

    	$add_args   = $args['add_args'];
    	$r          = '';
    	$page_links = array();
    	$dots       = false;

    	if ( $args['prev_next'] && $current && 1 < $current ) :
    		$link = str_replace( '%_%', 2 === $current ? '' : $args['format'], $args['base'] );
    		$link = str_replace( '%#%', $current - 1, $link );
    		if ( $add_args ) {
    			$link = add_query_arg( $add_args, $link );
    		}
    		$link .= $args['add_fragment'];

    		$page_links[] = sprintf(
    			'<a class="prev page-numbers" href="%s">%s</a>',
    			/**
    			 * Filters the paginated links for the given archive pages.
    			 *
    			 * @since 3.0.0
    			 *
    			 * @param string $link The paginated link URL.
    			 */
    			esc_url( apply_filters( 'paginate_links', $link ) ),
    			$args['prev_text']
    		);
    	endif;

    	for ( $n = 1; $n <= $total; $n++ ) :
    		if ( $n === $current ) :
    			$page_links[] = sprintf(
    				'<span aria-current="%s" class="page-numbers current">%s</span>',
    				esc_attr( $args['aria_current'] ),
    				$args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number']
    			);

    			$dots = true;
    		else :
    			if ( $args['show_all'] || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
    				$link = str_replace( '%_%', 1 === $n ? '' : $args['format'], $args['base'] );
    				$link = str_replace( '%#%', $n, $link );
    				if ( $add_args ) {
    					$link = add_query_arg( $add_args, $link );
    				}
    				$link .= $args['add_fragment'];

    				$page_links[] = sprintf(
    					'<a class="page-numbers" href="%s">%s</a>',
    					/** This filter is documented in wp-includes/general-template.php */
    					esc_url( apply_filters( 'paginate_links', $link ) ),
    					$args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number']
    				);

    				$dots = true;
    			elseif ( $dots && ! $args['show_all'] ) :
    				$page_links[] = '<span class="page-numbers dots">' . __( '&hellip;' ) . '</span>';

    				$dots = false;
    			endif;
    		endif;
    	endfor;

    	if ( $args['prev_next'] && $current && $current < $total ) :
    		$link = str_replace( '%_%', $args['format'], $args['base'] );
    		$link = str_replace( '%#%', $current + 1, $link );
    		if ( $add_args ) {
    			$link = add_query_arg( $add_args, $link );
    		}
    		$link .= $args['add_fragment'];

    		$page_links[] = sprintf(
    			'<a class="next page-numbers" href="%s">%s</a>',
    			/** This filter is documented in wp-includes/general-template.php */
    			esc_url( apply_filters( 'paginate_links', $link ) ),
    			$args['next_text']
    		);
    	endif;

    	switch ( $args['type'] ) {
    		case 'array':
    			return $page_links;

    		case 'list':
    			$r .= "<ul class='page-numbers'>\n\t<li>";
    			$r .= implode( "</li>\n\t<li>", $page_links );
    			$r .= "</li>\n</ul>\n";
    			break;

    		default:
    			$r = implode( "\n", $page_links );
    			break;
    	}

    	/**
    	 * Filters the HTML output of paginated links for archives.
    	 *
    	 * @since 5.7.0
    	 *
    	 * @param string $r    HTML output.
    	 * @param array  $args An array of arguments. See paginate_links()
    	 *                     for information on accepted arguments.
    	 */
    	$r = apply_filters( 'paginate_links_output', $r, $args );

    	return $r;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/general-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/general-template.php#L4665)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/general-template.php#L4665-L4859)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/paginate_links/?output_format=md#hooks)󠁿

 [apply_filters( ‘paginate_links’, string $link )](https://developer.wordpress.org/reference/hooks/paginate_links/)

Filters the paginated links for the given archive pages.

 [apply_filters( ‘paginate_links_output’, string $r, array $args )](https://developer.wordpress.org/reference/hooks/paginate_links_output/)

Filters the HTML output of paginated links for archives.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/paginate_links/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_parse_str()](https://developer.wordpress.org/reference/functions/wp_parse_str/)`wp-includes/formatting.php` |

Parses a string into variables to be stored in an array.

  | 
| [untrailingslashit()](https://developer.wordpress.org/reference/functions/untrailingslashit/)`wp-includes/formatting.php` |

Removes trailing forward slashes and backslashes if they exist.

  | 
| [urlencode_deep()](https://developer.wordpress.org/reference/functions/urlencode_deep/)`wp-includes/formatting.php` |

Navigates through an array, object, or scalar, and encodes the values to be used in a URL.

  | 
| [get_query_var()](https://developer.wordpress.org/reference/functions/get_query_var/)`wp-includes/query.php` |

Retrieves the value of a query variable in the [WP_Query](https://developer.wordpress.org/reference/classes/wp_query/) class.

  | 
| [get_pagenum_link()](https://developer.wordpress.org/reference/functions/get_pagenum_link/)`wp-includes/link-template.php` |

Retrieves the link for a page number.

  | 
| [user_trailingslashit()](https://developer.wordpress.org/reference/functions/user_trailingslashit/)`wp-includes/link-template.php` |

Retrieves a trailing-slashed string if the site is set for adding trailing slashes.

  | 
| [WP_Rewrite::using_index_permalinks()](https://developer.wordpress.org/reference/classes/wp_rewrite/using_index_permalinks/)`wp-includes/class-wp-rewrite.php` |

Determines whether permalinks are being used and rewrite module is not enabled.

  | 
| [WP_Rewrite::using_permalinks()](https://developer.wordpress.org/reference/classes/wp_rewrite/using_permalinks/)`wp-includes/class-wp-rewrite.php` |

Determines whether permalinks are being used.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [esc_url()](https://developer.wordpress.org/reference/functions/esc_url/)`wp-includes/formatting.php` |

Checks and cleans a URL.

  | 
| [esc_attr()](https://developer.wordpress.org/reference/functions/esc_attr/)`wp-includes/formatting.php` |

Escaping for HTML attributes.

  | 
| [trailingslashit()](https://developer.wordpress.org/reference/functions/trailingslashit/)`wp-includes/formatting.php` |

Appends a trailing slash.

  | 
| [wp_parse_args()](https://developer.wordpress.org/reference/functions/wp_parse_args/)`wp-includes/functions.php` |

Merges user defined arguments into defaults array.

  | 
| [add_query_arg()](https://developer.wordpress.org/reference/functions/add_query_arg/)`wp-includes/functions.php` |

Retrieves a modified URL query string.

  | 
| [number_format_i18n()](https://developer.wordpress.org/reference/functions/number_format_i18n/)`wp-includes/functions.php` |

Converts float number to format based on the locale.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

[Show 11 more](https://developer.wordpress.org/reference/functions/paginate_links/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/paginate_links/?output_format=md#)

| Used by | Description | 
| [get_the_posts_pagination()](https://developer.wordpress.org/reference/functions/get_the_posts_pagination/)`wp-includes/link-template.php` |

Retrieves a paginated navigation to next/previous set of posts, when applicable.

  | 
| [WP_User_Search::do_paging()](https://developer.wordpress.org/reference/classes/wp_user_search/do_paging/)`wp-admin/includes/deprecated.php` |

Handles paging for the user search query.

  | 
| [media_upload_library_form()](https://developer.wordpress.org/reference/functions/media_upload_library_form/)`wp-admin/includes/media.php` |

Outputs the legacy media upload form for the media library.

  | 
| [wp_nav_menu_item_post_type_meta_box()](https://developer.wordpress.org/reference/functions/wp_nav_menu_item_post_type_meta_box/)`wp-admin/includes/nav-menu.php` |

Displays a meta box for a post type menu item.

  | 
| [wp_nav_menu_item_taxonomy_meta_box()](https://developer.wordpress.org/reference/functions/wp_nav_menu_item_taxonomy_meta_box/)`wp-admin/includes/nav-menu.php` |

Displays a meta box for a taxonomy menu item.

  | 
| [paginate_comments_links()](https://developer.wordpress.org/reference/functions/paginate_comments_links/)`wp-includes/link-template.php` |

Displays or retrieves pagination links for the comments on the current post.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/paginate_links/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/paginate_links/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/paginate_links/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.9.0](https://developer.wordpress.org/reference/since/4.9.0/) | Added the `aria_current` argument. | 
| [2.1.0](https://developer.wordpress.org/reference/since/2.1.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/paginate_links/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 8 content](https://developer.wordpress.org/reference/functions/paginate_links/?output_format=md#comment-content-418)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/paginate_links/#comment-418)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fpaginate_links%2F%23comment-418)
     Vote results for this note: 8[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fpaginate_links%2F%23comment-418)
 4.  **Example With a Custom Query**
      When querying a loop with new [WP_Query](https://developer.wordpress.org/reference/classes/wp_query/)
     set the `total` parameter to the `max_num_pages` property of the `WP_Query` object.
 5.  Example of a custom query:
 6.      ```php
         <?php
         //Protect against arbitrary paged values
         $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
     
         $args = array(
         	'posts_per_page' => 5,
         	'category_name' => 'gallery',
         	'paged' => $paged,
         );
     
         $the_query = new WP_Query( $args );
         ?>
         <!-- the loop etc.. -->
         ```
     
 7.  Example of `paginate_links` parameters adapted to the custom query above:
 8.      ```php
         <?php
         $big = 999999999; // need an unlikely integer
     
         echo paginate_links( array(
         	'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
         	'format' => '?paged=%#%',
         	'current' => max( 1, get_query_var('paged') ),
         	'total' => $the_query->max_num_pages
         ) );
         ?>
         ```
     
 9.   * When using PHP >= 8, the types are important. You have to use $big = ‘999999999’;,
        otherwise the first string replacement will fail. Other then that, the example
        works perfectly.
      * [Iulia Cazan](https://profiles.wordpress.org/iulia-cazan/) [3 years ago](https://developer.wordpress.org/reference/functions/paginate_links/#comment-6543)
 10.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fpaginate_links%2F%3Freplytocom%3D418%23feedback-editor-418)
 11.  [Skip to note 9 content](https://developer.wordpress.org/reference/functions/paginate_links/?output_format=md#comment-content-419)
 12.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/paginate_links/#comment-419)
 13. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fpaginate_links%2F%23comment-419)
     Vote results for this note: 5[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fpaginate_links%2F%23comment-419)
 14. **Improving Accessibility**
      To add context to the numbered links to ensure that
     screen reader users understand what the links are for:
 15.     ```php
         <?php
         global $wp_query;
     
         $big = 999999999; // need an unlikely integer
         $translated = __( 'Page', 'mytextdomain' ); // Supply translatable string
     
         echo paginate_links( array(
         	'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,
                 'before_page_number' => '<span class="screen-reader-text">'.$translated.' </span>'
         ) );
         ?>
         ```
     
 16.  * This should be the default to avoid a lawsuit (Which we’re going through right
        now so don’t think it wont happen to you!). Additionally you need the previous
        and next links to say what they are:
      *     ```php
             'prev_text' =&gt; is_rtl() ? 'Previous Page &amp;rarr;' : 'Previous Page &amp;larr;', 'next_text' =&gt; is_rtl() ? 'Next Page &amp;larr;' : 'Next Page &amp;rarr;', 
            ```
        
      * [thedoctore](https://profiles.wordpress.org/thedoctore/) [4 years ago](https://developer.wordpress.org/reference/functions/paginate_links/#comment-5801)
      * When using PHP 8, the types are important. You have to use `$big = '999999999';`,
        otherwise the first string replacement will fail.
      * [Iulia Cazan](https://profiles.wordpress.org/iulia-cazan/) [3 years ago](https://developer.wordpress.org/reference/functions/paginate_links/#comment-6542)
 17.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fpaginate_links%2F%3Freplytocom%3D419%23feedback-editor-419)
 18.  [Skip to note 10 content](https://developer.wordpress.org/reference/functions/paginate_links/?output_format=md#comment-content-3862)
 19.   [Hay](https://profiles.wordpress.org/huskyr/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/paginate_links/#comment-3862)
 20. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fpaginate_links%2F%23comment-3862)
     Vote results for this note: 5[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fpaginate_links%2F%23comment-3862)
 21. You might notice that `paginate_links` always gives back HTML, even if you’re 
     setting `type` to array, which makes it a bit hard if you want to completely customise
     the HTML structure of your pagination. I wrote a little function that gives you
     back an array of objects instead of HTML that might make this a bit easier.
 22.     ```php
         function wpdocs_get_paginated_links( $query ) {
             // When we're on page 1, 'paged' is 0, but we're counting from 1,
             // so we're using max() to get 1 instead of 0
             $currentPage = max( 1, get_query_var( 'paged', 1 ) );
     
             // This creates an array with all available page numbers, if there
             // is only *one* page, max_num_pages will return 0, so here we also
             // use the max() function to make sure we'll always get 1
             $pages = range( 1, max( 1, $query->max_num_pages ) );
     
             // Now, map over $pages and return the page number, the url to that
             // page and a boolean indicating whether that number is the current page
             return array_map( function( $page ) use ( $currentPage ) {
                 return ( object ) array(
                     "isCurrent" => $page == $currentPage,
                     "page" => $page,
                     "url" => get_pagenum_link( $page )
                 );
             }, $pages );
         }
         ```
     
 23. And use it like this (given that `$query` is the name of your custom query):
 24.     ```php
         <ul>
             <?php foreach( wpdocs_get_paginated_links( $query ) as $link ) : ?>
             <li>
                 <?php if ( $link->isCurrent ): ?>
                     <strong><?php _e( $link->page ) ?></strong>
                 <?php else : ?>
                     <a href="<?php esc_attr_e( $link->url ) ?>">
                         <?php _e( $link->page ) ?>
                     </a>
                 <?php endif; ?>
             </li>
             <?php endforeach; ?>
         </ul>
         ```
     
 25.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fpaginate_links%2F%3Freplytocom%3D3862%23feedback-editor-3862)
 26.  [Skip to note 11 content](https://developer.wordpress.org/reference/functions/paginate_links/?output_format=md#comment-content-2910)
 27.   [Binsaifullah](https://profiles.wordpress.org/binsaifullah/)  [  8 years ago  ](https://developer.wordpress.org/reference/functions/paginate_links/#comment-2910)
 28. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fpaginate_links%2F%23comment-2910)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fpaginate_links%2F%23comment-2910)
 29.     ```php
         // first create a function 
         function pagainate_link_function(){
         	global $wp_query;
         	echo paginate_links(array(
         		'current'=>max(1,get_query_var('paged')),
         		'total'=>$wp_query->max_num_pages,
         		'type'=>'list', //default it will return anchor
         	));
         }
     
         // Now call this function in your desired place
         ```
     
 30.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fpaginate_links%2F%3Freplytocom%3D2910%23feedback-editor-2910)
 31.  [Skip to note 12 content](https://developer.wordpress.org/reference/functions/paginate_links/?output_format=md#comment-content-3126)
 32.   [Sean Leavey](https://profiles.wordpress.org/seanleavey/)  [  7 years ago  ](https://developer.wordpress.org/reference/functions/paginate_links/#comment-3126)
 33. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fpaginate_links%2F%23comment-3126)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fpaginate_links%2F%23comment-3126)
 34. Note that the `base` argument should be fully qualified, e.g. `https://example.
     com/my-post/%_%#some-id`, not just `%_%#some-id`.
 35. If the `base` argument doesn’t contain the absolute URL, then when you are on 
     the second page the link to the first page will not work; instead it will link
     to the current page. This is because the “Previous” link is set to the `base` 
     argument with the `%_%` part removed, and no extra `?paged=%#%` part added. Your
     browser then interprets this to mean the current page, so the “Previous” link 
     points to the current page.
 36.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fpaginate_links%2F%3Freplytocom%3D3126%23feedback-editor-3126)
 37.  [Skip to note 13 content](https://developer.wordpress.org/reference/functions/paginate_links/?output_format=md#comment-content-417)
 38.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/paginate_links/#comment-417)
 39. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fpaginate_links%2F%23comment-417)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fpaginate_links%2F%23comment-417)
 40. **Basic Example**
      To add pagination to your search results and archives, you 
     can use the following example:
 41.     ```php
         <?php
         global $wp_query;
     
         $big = 999999999; // need an unlikely integer
     
         echo paginate_links( array(
         	'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
         ) );
         ?>
         ```
     
 42.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fpaginate_links%2F%3Freplytocom%3D417%23feedback-editor-417)
 43.  [Skip to note 14 content](https://developer.wordpress.org/reference/functions/paginate_links/?output_format=md#comment-content-2573)
 44.   [Chetan Prajapati](https://profiles.wordpress.org/chetan200891/)  [  8 years ago  ](https://developer.wordpress.org/reference/functions/paginate_links/#comment-2573)
 45. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fpaginate_links%2F%23comment-2573)
     Vote results for this note: -3[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fpaginate_links%2F%23comment-2573)
 46.     ```php
         <?php
         global $wp_query;
     
         $big = 999999999; // need an unlikely integer
     
         echo paginate_links( array(
             '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
         ) );
         ?>
         ```
     
 47. Aligned array items properly based on WPCS.
 48.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fpaginate_links%2F%3Freplytocom%3D2573%23feedback-editor-2573)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fpaginate_links%2F)
before being able to contribute a note or feedback.