Make WordPress Core

Changeset 56057


Ignore:
Timestamp:
06/27/2023 08:09:29 AM (12 months ago)
Author:
audrasjb
Message:

Twenty Nineteen: Add fragment ID to paginated links.

This changeset adds the #content fragment identifier to paginated links so the screen scrolls down to the content section when clicking on pagination links
located on paginated pages.

Props laurelfulford, mukesh27, joyously, poena, alvitazwar052, oglekler, audrasjb.
Fixes #45920.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentynineteen/inc/template-functions.php

    r55963 r56057  
    224224}
    225225add_filter( 'wp_nav_menu_objects', 'twentynineteen_add_mobile_parent_nav_menu_items', 10, 2 );
     226
     227/**
     228 * Adds a fragment identifier (to the content) to paginated links.
     229 *
     230 * @since Twenty Nineteen 2.6
     231 *
     232 * @param string $link The page number HTML output.
     233 * @param int    $i    Page number for paginated posts' page links.
     234 * @return string Formatted output in HTML.
     235 */
     236function twentynineteen_link_pages_link( $link, $i ) {
     237    if ( $i > 1 && preg_match( '/href="([^"]*)"/', $link, $matches ) ) {
     238        $link = str_replace( $matches[1], $matches[1] . '#content', $link );
     239    }
     240    return $link;
     241}
     242add_filter( 'wp_link_pages_link', 'twentynineteen_link_pages_link', 10, 2 );
Note: See TracChangeset for help on using the changeset viewer.