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
This commit is contained in:
Jb Audras
2023-06-27 08:09:29 +00:00
parent f0f0be74f2
commit 456ebf5adb

View File

@@ -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 );