wp-includes/general-template.php:4665Retrieves paginated links for archive post pages.
$argsstring|arrayoptional''$basestringdefault: empty
$formatstringdefault: empty
$totalintdefault: is the value WP_Query's max_num_pages or 1
$currentintdefault: is 'paged' query var or 1
$aria_currentstringdefault: is 'page'
$show_allbooldefault: false
$end_sizeintdefault: 1
$mid_sizeintdefault: 2
$prev_nextbooldefault: true
$prev_textstringdefault: '« Previous'
$next_textstringdefault: 'Next »'
$typestringdefault: is 'plain'
$add_argsarraydefault: false
$add_fragmentstringdefault: empty
$before_page_numberstringdefault: empty
$after_page_numberstringdefault: empty
string|string[]|null4 hooks fire while paginate_links() runs, in this order:
Filters the paginated links for the given archive pages.
Filters the paginated links for the given archive pages.
Filters the paginated links for the given archive pages.
Filters the HTML output of paginated links for archives.
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' => __( '« Previous' ), 'next_text' => __( 'Next »' ), '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; }Introduced in 2.1.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
string|string[]|void to string|string[]|null.verified against sourcesrc/wp-includes/general-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.