Forums › Forums › Search & Filter Pro › Canonical tags on paginated pages – WPSEO
Tagged: canonical tags, pagination, seo
- This topic has 4 replies, 4 voices, and was last updated 7 years, 1 month ago by Trevor.
-
Anonymous(Private) November 27, 2015 at 5:07 pm #30910
Hi,
I’m using “Search & Filter Pro” on my website Home Page (with a shortcode) and on my search.php template. And I’m very happy with it !
I noticed a little compatibility problem with SEO plugins like “WordPress SEO” from Yoast.
“Wordppress SEO” from Yoast automatically adds canonical tags on paginated pages like this :
<link rel="prev" href="http://mydomain.com/page/1" /> <link rel="next" href="http://mydomain.com/page/3" />
or that
<link rel="prev" href="http://mydomain.com/search/page/1" /> <link rel="next" href="http://mydomain.com/search/page/3" />
But these URL send 404 errors because “Search & Filter Pro” doesn’t use the default WordPress pagination.
I tried unsuccessfully to use the “WordPress SEO” filters (
wpseo_prev_rel_link
&wpseo_next_rel_link
) to customize these canonical URLs to look like this:<link rel="prev" href="http://mydomain.com/?sf_paged=1" /> <link rel="next" href="http://mydomain.com/?sf_paged=3" />
and
<link rel="prev" href="http://mydomain.com/search/?sf_paged=1" /> <link rel="next" href="http://mydomain.com/search/?sf_paged=3" />
For now, I’m using a function to prevent addition of prev/next rel link by WordPress SEO (https://gist.github.com/tacoverdo/7102453) but it would be nice to work it out ! 😉
Do you have a fix for that ?
Thank you.
Anonymous(Private) November 27, 2015 at 6:03 pm #30912I almost found a solution:
I used a custom function to generate new canonical tags on paginated pages:
function wpseo_custom_rel_next_prev_canonical_links(){ global $paged; if ( get_previous_posts_link() ) { echo "<link rel='prev' href='".get_pagenum_link( $paged - 1 )."' />"; } if ( get_next_posts_link() ) { echo "<link rel='next' href='".get_pagenum_link( $paged +1 )."' />"; } } add_action( 'wp_head', 'wpseo_custom_rel_next_prev_canonical_links' );
It works on my search page which use search.php. But it return nothing on my home page which use a shortcode to insert “Search & Filter” results. I think
get_previous_posts_link()
andget_next_posts_link()
return false or$paged
doesn’t exist on this page…Anonymous(Private) May 3, 2017 at 7:24 am #106093Hi,
Did you ever figured this out? I am also getting error 400 because the paginated pages of the shop are like this :
http://www.teambuildingmadeeasy.com.au/shop/?sf_paged=4
I have over 2000 of error 400 links because of this and my website dropped in rank.
Is there any solution to this.
Please help.
Trevor(Private) October 11, 2017 at 11:46 am #135862As it is WP SEO adding these, you would need to use their filters to change what is output.
See these pages as an example:
https://gist.github.com/amboutwe/2aa7dcc9a38986e11fac68c7306cc091
https://kb.yoast.com/kb/is-the-plugin-compatible-with-paginated-content/
If you explained what you need on their help forums, I am sure you would get some better examples.
-
AuthorPosts