Created
April 29, 2022 17:42
-
-
Save bdeleasa/eb50ee408ef90c86c14fb186eb4f2bcd to your computer and use it in GitHub Desktop.
A simple filter to fix any and all pagination using paginate_links so /page/1/ is stripped from the first item URL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'paginate_links', 'wpfixpagination_remove_page_1_deadlinks', 10, 2 ); | |
/** | |
* Finds any instance of a /page/1/ link in the navigation and removes it cause SEO people and search engines | |
* don't like redirects apparently. :) Thanks StackOverlow! @see below | |
* | |
* @see https://stackoverflow.com/questions/46195352/woocommerce-pagination-prevent-301-redirect-on-page-1 | |
* | |
* @since 1.0.0 | |
* | |
* @param $link string | |
* @return string | |
*/ | |
function wpfixpagination_remove_page_1_deadlinks($link) { | |
$pos = strpos($link, 'page/1/'); | |
if( $pos !== false ) { | |
$link = substr($link, 0, $pos); | |
} | |
return $link; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment