Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

SEO optimize pagination with rel="prev" & rel="next" #183

Open
Rio517 opened this Issue Sep 15, 2011 · 25 comments

Comments

Projects
None yet

Rio517 commented Sep 15, 2011

I wanted to propose that will_paginate include a view helper for SEO optimization, per a recent official Google blog post

<link rel="prev" href="http://www.example.com/article?story=abc&page=1&sessionid=123" />
<link rel="next" href="http://www.example.com/article?story=abc&page=3&sessionid=123" />

link: http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html

Thanks!

Owner

mislav commented Sep 15, 2011

Hey! That would be valid use if we didn't have actual hyperlinks with rel="prev/next", which we have for a long time now each time you generate pagination with will_paginate().

Per HTML5 spec, these rel values are a good enough hint to the user agent that these point to the resources that represent previous/next pages of results. We shouldn't need additional <link> elements in the <head>.

@mislav mislav closed this Sep 15, 2011

If I were to do this how would it be implemented?

"Google indexing of paginated content, rel="next" and rel="prev" declarations belong in the <head> section, not in the body as anchor links."

http://www.google.com/support/forum/p/Webmasters/thread?tid=344378292ff91e8d&hl=en

forest commented May 10, 2012

You would think that rel next/prev on the actual links would be good enough, but not so according to Google.
http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html

Here is an example from kaminari.
https://github.com/amatsuda/kaminari/pull/200/files

That feature would be very much appreciated. As others stated here, google only considers relevant the rel attributes inside a link tag, not in an 'a' tag. I am going to do a dirty patch for my project. If things turn out well, I can make a pull request.

csgavino commented Jun 6, 2013

Bump, has this ever been solved?

Owner

mislav commented Jun 6, 2013

Not that I know of. The solution would require a separate will_paginate helper method to generate the <link> tags, as well as a method to inject those in the current page's <head>. This is not straightforward to do in Rails, and would require changes to your app's layout(s).

Fernan2 commented Jul 15, 2013

Our SEO has just asked us for this; and although Kaminari already supports, Kaminari lacks of anchoring support, which is very useful for us... I will also appreciate this, but in the meantime, I'll ask @tganzarolli for his dirty patch.

Owner

mislav commented Jul 15, 2013

Alright, gonna reopen this and anyone is welcome to take a stab at the implementation.

@mislav mislav reopened this Jul 15, 2013

Pretty much straight port of Kaminari's method in my pull request #324

Fernan2 commented Oct 7, 2013

It will be nice if you could merge @lloydmeta 's PR...

Thks!

Just checking in on the status of this pull request. Any chance of it being included?

I would like this merged as well!

johnpash commented Feb 4, 2015

👍

subimage commented Apr 1, 2015

MISLAV WHY U NO MERGE :(

scruti commented Apr 1, 2015

🕦

aleks commented Aug 5, 2015

We are in need of this too! A merge would be kinda cool. 👍

👍

👍

alpemaca commented Dec 1, 2015

👍

@jonatack jonatack added a commit to jonatack/will_paginate that referenced this issue Dec 6, 2015

@jonatack jonatack Add #pagination_link_tags helper method
This is a port of PR #324 by @lloydmeta in will_paginate:

mislav#324

in response to issue #183:

'SEO optimize pagination with rel="prev" & rel="next"'

mislav#183
28fa48f
Contributor

jonatack commented Dec 6, 2015

Thanks @lloydmeta for the PR. I merged it into my version of will_paginate for Ruby 2.2/Rails 5.

Folks, +1 comments aren't helpful. If you want this feature (or any other), just fork the gem and merge it in 😃

@mpolakis mpolakis added a commit to mpolakis/will_paginate that referenced this issue Mar 11, 2016

@jonatack @mpolakis jonatack + mpolakis Add #pagination_link_tags helper method
This is a port of PR #324 by @lloydmeta in will_paginate:

mislav#324

in response to issue #183:

'SEO optimize pagination with rel="prev" & rel="next"'

mislav#183
c388e3a

Thanks @lloydmeta and @jonatack for your work on this issue. Also, thanks @mislav for building this wonderful gem. Any idea if you actually intend to merge this? If yes, when? Thanks.

dignoe commented Apr 21, 2016

I've made a gist on how to monkey patch will_paginate v3.0.7 to add rel="next" & rel="prev" links to your header. I only use this on pages that require custom link generation, so this also includes a patch to use a custom url generator if a specific option is passed.

https://gist.github.com/dignoe/0f76e81949b46e48e4ff4f992aa93aeb

erpe commented Sep 9, 2016

if you don't like monkey patching: a simple view-helper as a rails-railtie: https://github.com/erpe/rails_will_paginate_seo_helper

@christemple christemple pushed a commit to notonthehighstreet/will_paginate that referenced this issue Oct 6, 2016

@jonatack jonatack + Christopher Temple and Geza Kiss Add #pagination_link_tags helper method
This is a port of PR #324 by @lloydmeta in will_paginate:

mislav#324

in response to issue #183:

'SEO optimize pagination with rel="prev" & rel="next"'

mislav#183
fdb95d4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment