Hello,

Tell me how you can replace the URL http://test.com/page/10 at http://test.com/page/11 . That is, add 1? I use php and WP.

I get links and how to add 1 fails.

function add_prev_next_links() { global $post; if ( is_front_page() ) { $ur = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; preg_match('#page/(\d+)#', $_SERVER['REQUEST_URI'], $match_page); $paged = $match_page[1]; if($paged){ echo '<link rel="next" href="' . $ur .'" />' . "\n"; echo '<link rel="prev" href="' . $ur . '" />' . "\n"; } } } add_action( 'wp_head', 'add_prev_next_links'); 
  • one
    Increment match_page variable - not? - Mikhail Alekseevich
  • In php at the moment is not strong, I do not know a lot of things. Thanks for the answer, I'll try. - webEugene
  • with increment understood, and how to overwrite? - webEugene
  • overwrite what? :) - Mikhail Alekseevich
  • $ ur = 'http: //'. $ _SERVER ['HTTP_HOST']. $ _SERVER ['REQUEST_URI']; preg_match ('# page / (\ d +) #', $ _SERVER ['REQUEST_URI'], ++ $ match_page); - Mikhail Alekseevich

2 answers 2

 function add_prev_next_links() { global $wp_query; if (is_front_page()) { $currentPage = get_query_var('paged') ? get_query_var('paged') : 1; $link = get_page_link(); if ($currentPage > 1) { echo '<link rel="prev" href="' . $link . 'page/' . ($currentPage-1) . '" />' . "\n"; } if ($currentPage < $wp_query->max_num_pages) { echo '<link rel="next" href="' . $link . 'page/' . ($currentPage+1) . '" />' . "\n"; } } } add_action( 'wp_head', 'add_prev_next_links'); 
  • Not sure what the issue is. How could he give such a detailed answer? :) - Mikhail Alekseevich
  • In my case, this does not work, unfortunately. The site is made a little sloppy ( - webEugene

Decided so:

 function add_prev_next_links() { global $post; if ( is_front_page() ) { $ur = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; preg_match('#page/(\d+)#', $_SERVER['REQUEST_URI'], $match_page); $paged = $match_page[1]; $x = $match_page[1] + 1; $software = str_replace($match_page[1], $x, $ur); if($paged){ echo '<link rel="next" href="' . $software .'" />' . "\n"; echo '<link rel="prev" href="' . $ur . '" />' . "\n"; } } } add_action( 'wp_head', 'add_prev_next_links');