0

I have a Wordpress site with some posts splitted in pages. I added post pagination via this code:

Single.php:

<?php wp_link_pages(array( 'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentythirteen' ) . '</span>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>', 'next_or_number' => 'next_and_number', 'separator' => '', 'nextpagelink' => __( '&raquo;' ), 'previouspagelink' => __( '&laquo;' ), 'pagelink' => '%')); ?>
                                    </div>

Functions.php:

add_filter('wp_link_pages_args', 'wp_link_pages_args_prevnext_add');
/**
 * Paginacja w postach
 */
function wp_link_pages_args_prevnext_add($args)
{
    global $page, $numpages, $more, $pagenow;
    if (!$args['next_or_number'] == 'next_and_number') 
        return $args; # exit early
    $args['next_or_number'] = 'number'; # keep numbering for the main part
    if (!$more)
        return $args; # exit early
    if($page-1) # there is a previous page
        $args['before'] .= _wp_link_page($page-1)
            . $args['link_before']. $args['previouspagelink'] . $args['link_after'] . '</a>'
        ;
    if ($page<$numpages) # there is a next page
        $args['after'] = _wp_link_page($page+1)
            . $args['link_before'] . $args['nextpagelink'] . $args['link_after'] . '</a>'
            . $args['after']
        ;
    return $args;
}

I really need to add "rel=next" and "rel=prev" tags for those paginated pages. I need to do it so Google will be able to distinguish page 1,2,3 etc (just like in this tutorial).

The only problem is that I don't know where should I add these tags. Does anyone have an idea how can I modify the code above?

Here's my example post with pagination.

Thank you, Kacper

  • You already have necessary information in the document head: <link rel="next" href="https://www.gameron.pl/recenzje/red-dead-redemption-2/2/" />. And that's exactly what Google wants to see: Indicating paginated content to Google – Max Yudin Dec 17 '18 at 16:13

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.