How to add link rel tags on paginated posts?

I’m using the following code in functions.php to add rel prev/next tags to paginated contents:

function add_rel_nextprev_to_paginated_content()
global $paged;
if ( get_previous_posts_link() ) { ?><link rel="prev" href="<?php echo get_pagenum_link( $paged - 1 ); ?>"><?php }
if ( get_next_posts_link() ) { ?><link rel="next" href="<?php echo get_pagenum_link( $paged + 1 ); ?>"><?php }
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
add_action('wp_head', 'add_rel_nextprev_to_paginated_content');

This works well for categories, tags and other content, but not the posts that were split into multiple pages by WP’s tag.

However, I can’t find the right function to call the next page of a paginated post.

Any help is highly appreciated.

New User Asked on September 19, 2018 in Customizations.
Add Comment
1 Answer(s)

After some research I found a code snippet that exactly does the job as desired.

See for details and further explanations.

New User Answered on September 19, 2018.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service. | Learn how to add/edit code.