Created
March 26, 2019 01:28
-
-
Save gatespace/7d5739adfe88d028df602eb7e9de60df to your computer and use it in GitHub Desktop.
WordPressの検索結果ページ+ページネーション(WP PageNavi含む)のリンクで `/page/数字` をやめ、 `?s=word&paged=2` のリンクにする
This file contains hidden or 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( 'get_pagenum_link', 'my_search_paginate_links' ); | |
add_filter( 'paginate_links', 'my_search_paginate_links' ); | |
function my_search_paginate_links( $link ) { | |
if ( is_search() ) { | |
$pattern = '/page\/(\d+)\/\?s=([^\/]+)/i'; | |
if ( preg_match( $pattern, $link ) ) { | |
$link = preg_replace( $pattern, '?s=$2&paged=$1', $link ); | |
} | |
} | |
return $link; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment