I’ve just noticed that on my paginated posts, only the main page gets indexed in Google. The paginated posts “post-title/2” and “post-title/3” for example, do not get indexed.
On closer inspection, it appears that WordPress creates the same canonical URL for all pages in a paginated sequence. So, the canonical for page 2 is the same for page 1, etc. So when google crawls page 2+, the canonical directs them back to the first page.
Any clues how to go about resolving this to get a more intelligent canonical url on paginated posts and pages?
You will need to replace the default
rel_canonical
function to do this:This new function adds gets the paginated page from the URL and adds it to the canonical link. It will also add next and previous links to the adjacent pages so Google knows
Also, if you use Yoast’s WordPress SEO plugin you will not need this snippet, as the plugin handles canonical links for you.