It’s important to include the rel=”prev” & rel=”next” meta tags in your WordPress blog. These meta tags will show Google the relationships of documents that span over multiple pages and distinguish them as a series.
This is great for SEO and helps Google properly index your information. Proper indexing means more relevant results to users and more targeted traffic to your site.
It’s quite simple to add these meta tags to the
section on your blog.What you need to do is open your theme functions.php file and add :
function cor_rel_next_prev_pagination() {
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', 'cor_rel_next_prev_pagination');
To check to see if it’s working, navigate to page 2 on your blog and view the source.
You should see something like this :
<link rel="prev" href="http://example.com/">
<link rel="next" href="http://example.com/page/2/">
More information can be found on the Google Webmaster Blog.
Thanks, very helpful, I spend a lot of time searching that.
Works like a charm on category pages and author pages too – anywhere with pagination! Thank you very much
Thanks! Just one question: how can I make this code work for comments pagination as well?
Thanks. This is important right now with new changes from Google.
Thanks! but I am using yoast and i am using static homepage where there is no pagination and it show up. How I can remove it from homepage.
@Mido You’ll need to do something like this then :
if ( !is_front_page() )
{
remove_action(‘wp_head’, ‘adjacent_posts_rel_link_wp_head’);
add_action(‘wp_head’, ‘cor_rel_next_prev_pagination’);
}
While the rel=”prev” seems to be working, rel=”next” does not.
I see that you are using the Yoast SEO plugin – this functionality should already be a built in option (I believe you just need to enable it).
It is set to work, but seems to only be working with posts and categories. I have confirmed this with Toast support. I still trying switching off toast pagination and see if that fixes it.
Hello, did you find the soulution? I’m in the same situation.
I did actually find the solution. I stopped using Yoast, as their plugin changed. For some reason they only use rel=”prev” and use a canonical link back to the first page. My problem with that is that Google created this, as many people were using a lot methods. Google specifically wanted to have this group paginated pages to be identified as part of a group of pages. Yoast solution really does that anymore. Their change is more focused on pointing to the first page.
Here is Google’s post on what they want:
https://webmasters.googleblog.com/2011/09/pagination-with-relnext-and-relprev.html
To make this happen, I have added the following code to my themes functions.php file.
<link rel="prev" href="” />
<link rel="next" href="” />
This code was found on:
http://wordpress.stackexchange.com/questions/36800/adding-rel-next-rel-prev-for-paginated-archives
In addition, I am using the all in one SEO plugin. You can click NO Pagination for cannonical URLS in general setting. This adds a NO Index attribute to paginated URLS, will add a canonical link to the first instance of the page, which is set to a self-refrencing URL.
Depending on the page structure you are using, you could also modify your robot.txt file. For instance, I was working on a client’s site, where paginated pages were in the following format
Paginated 2nd page: /?idxpage=2
In this instance I added a wildcard command to the robots.txt file.
Disallow .* ?idxpage=.*
If your URL structure is follows normal WordPress URL structure, you will not need to modify the robot.txt file.
Realmente material muito útil me ajudou bastante obrigado
Seja bem-vindo!