[wp-trac] [WordPress Trac] #63581: paginate_links: The current page should be an a element, not a span element

WordPress Trac noreply at wordpress.org
Wed Jun 25 14:13:46 UTC 2025


#63581: paginate_links: The current page should be an a element, not a span element
--------------------------+------------------------------
 Reporter:  wildworks     |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  General       |     Version:
 Severity:  normal        |  Resolution:
 Keywords:  2nd-opinion   |     Focuses:  accessibility
--------------------------+------------------------------

Comment (by iamadisingh):

 I've analyzed the `paginate_links()` function in
 https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-includes
 /general-template.php#L4627-4807 and would like to propose a backwards-
 compatible solution.

 **Current Issue**
 The current page is output as a `<span>` element:
 {{{#!php
 <?php
 $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']
 );
 }}}
 This creates accessibility issues as screen reader users cannot focus on
 the current page indicator.

 **Proposed Solution**
 Add a new link_current parameter to the $defaults array with backwards
 compatibility:
 {{{#!php
 <?php
 $defaults = array(
     // ...existing parameters...
     'link_current' => false, // NEW: Whether to link the current page for
 better accessibility
 );
 }}}
 Then update the current page logic to conditionally create a link:
 {{{#!php
 <?php
 if ( $n === $current ) :
     if ( $args['link_current'] ) {
         // Generate current page URL (same as current page)
         $current_link = str_replace( '%_%', 1 === $n ? '' :
 $args['format'], $args['base'] );
         $current_link = str_replace( '%#%', $n, $current_link );
         if ( $add_args ) {
             $current_link = add_query_arg( $add_args, $current_link );
         }
         $current_link .= $args['add_fragment'];

         $page_links[] = sprintf(
             '<a aria-current="%s" class="page-numbers current"
 href="%s">%s</a>',
             esc_attr( $args['aria_current'] ),
             esc_url( apply_filters( 'paginate_links', $current_link ) ),
             $args['before_page_number'] . number_format_i18n( $n ) .
 $args['after_page_number']
         );
     } else {
         // Keep existing span behavior as default (backwards
 compatibility)
         $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;
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63581#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list