From 456ebf5adb2c12f91fc6d1c9efc91543af98d5c1 Mon Sep 17 00:00:00 2001 From: Jb Audras Date: Tue, 27 Jun 2023 08:09:29 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@56057 602fd350-edb4-49c9-b593-d223f7449a82 --- .../twentynineteen/inc/template-functions.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/wp-content/themes/twentynineteen/inc/template-functions.php b/src/wp-content/themes/twentynineteen/inc/template-functions.php index de2fa088bb..536fbd3ee4 100644 --- a/src/wp-content/themes/twentynineteen/inc/template-functions.php +++ b/src/wp-content/themes/twentynineteen/inc/template-functions.php @@ -223,3 +223,20 @@ function twentynineteen_add_mobile_parent_nav_menu_items( $sorted_menu_items, $a return $amended_menu_items; } add_filter( 'wp_nav_menu_objects', 'twentynineteen_add_mobile_parent_nav_menu_items', 10, 2 ); + +/** + * Adds a fragment identifier (to the content) to paginated links. + * + * @since Twenty Nineteen 2.6 + * + * @param string $link The page number HTML output. + * @param int $i Page number for paginated posts' page links. + * @return string Formatted output in HTML. + */ +function twentynineteen_link_pages_link( $link, $i ) { + if ( $i > 1 && preg_match( '/href="([^"]*)"/', $link, $matches ) ) { + $link = str_replace( $matches[1], $matches[1] . '#content', $link ); + } + return $link; +} +add_filter( 'wp_link_pages_link', 'twentynineteen_link_pages_link', 10, 2 );