I’ve a customized search web page (searchpage.php
) utilizing pagination, and I’m tring so as to add traces like beneath dynamically to my header.php
inside <head></head>
tag for higher pagination search engine marketing.
<hyperlink rel="prev" href="https://www.instance.com/search/cats/web page/2/">
<hyperlink rel="subsequent" href="https://www.instance.com/search/cats/web page/4/">
Whereas doing this, I’ve used beneath code talked about right here in capabilities.php.
<?php
perform rel_next_prev(){
world $paged;
if ( get_previous_posts_link() ) { ?>
<hyperlink rel="prev" href="<?php echo get_pagenum_link( $paged - 1 ); ?>" /><?php
}
if ( get_next_posts_link() ) { ?>
<hyperlink rel="subsequent" href="<?php echo get_pagenum_link( $paged +1 ); ?>" /><?php
}
}
add_action( 'wp_head', 'rel_next_prev' );
?>
get_previous_posts_link()
works high-quality, however get_next_posts_link
does not work, after some investigation I consider it requires max_num_pages
parameter to work.
Now I’m not in a position to get max_num_pages
as a result of it’s in searchpage.php
.