Canonical URLs Causing Duplicate Content
-
Hello AJAX Load More Staff,
In some SEO analyzing tools, the canonical link push states causes duplicate content issues. For example, /blog/ and /blog/page/2 canonical tags are the same but shown as two different pages. Is there a way to fix this in the plugin?
Thank you,
-
Hi @graphettion,
Are you referring to the canonical URL in the<head>?Can you show me an example of where this is updated? Im assuming you feel the canonical URL should read /page/2/ ?
Yeah, that’s what I’m referring to. I’m not the best at explaining. 😛 I want /page/2, /page/3, etc canonical tags to be /blog.
Ex:
<link rel=”canonical” href=”https://example.com/blog/page/2″ />Should be:
<link rel=”canonical” href=”https://example.com/blog” />-
This reply was modified 9 years, 6 months ago by
graphettion.
No worries, i figured it out 🙂
I see what you mean, so you think the [plugin should update the <link /> tag when a pushstate or popstate happens?I checked a few sites that have standard paging and every time there was a paged URL the canonical URL was still the root url without the ‘/page/3/’ value.
Can you show me an example of another WordPress site that updates this canonical <link /> tag while paging?
I had the same problem. I solved it by redirecting (301 SEO friendly) the user/google-robot to the main-category page, and using Ajax Load More with unlimited posts argument (which is default setting as far as I remember).
add_action( 'template_redirect', 'wpse27119_template_redirect' ); function wpse27119_template_redirect() { /* Redirect user to main category if the URL contains "/page/" */ if ( strpos( $_SERVER['REQUEST_URI'], "/page/" ) !== false ) { global $wp_query; $category_id = $wp_query->get_queried_object()->term_id; wp_redirect( get_category_link( $category_id ) ); return false; } }wp_redirect( get_category_link( $category_id ) );should actually be:
wp_redirect( get_category_link( $category_id ), '301' );Awesome. I’ll try it tomorrow. Thank you unicco. I appreciate both your speedy responses.
The plugin is great by the way. Great job dcooney and the contributors.
It worked like a charm. Much thanks unicco. I also added it for the /blog page.
//Canonical Tags for AJAX Load More (Ex: /blog/page/2, /blog/page/3, all go to /blog) add_action( 'template_redirect', 'wpse27119_template_redirect' ); function wpse27119_template_redirect() { /* Redirect user to main category if the URL contains "/page/" */ if ( strpos( $_SERVER['REQUEST_URI'], "/page/" ) !== false ) { global $wp_query; $category_id = $wp_query->get_queried_object()->term_id; $blog_id = get_permalink(get_option( 'page_for_posts' )); wp_redirect( get_category_link( $category_id ), '301' ); wp_redirect( $blog_id, '301' ); return false; } }Actually renamed
$blog_idto$blog_urlto give it a more meaningful name.-
This reply was modified 9 years, 6 months ago by
graphettion.
Glad I could help.
You might wanna put some conditional tags in your code, to separate the two redirections. Just a suggestion.
For category you can use:
if ( is_category() ) { }For blog-page you can use:
if ( $wp_query->query['pagename'] == 'blog' ) { }I wish I fully understood what you guys are up to here!
Care to explain it in a TL;DR format? 🙂
-
This reply was modified 9 years, 6 months ago by
Darren Cooney.
Hey @dcooney, here’s a visual of what I’m talking about.
http://www.screencast.com/t/Drn2f2VddoQ (No Audio; May need to copy/paste in a new window)
This explains what I am wanting. Unicco helped me code it for both categories and blog now (which I am much appreciated).
Let me know if this helps explain.
-
This reply was modified 9 years, 6 months ago by
graphettion.
-
This reply was modified 9 years, 6 months ago by
graphettion.
-
This reply was modified 9 years, 6 months ago by
graphettion.
@unicco: How does this look?
function wpse27119_template_redirect() { /* Redirect user to main category if the URL contains "/page/" */ if ( strpos( $_SERVER['REQUEST_URI'], "/page/" ) !== false ) { global $wp_query; $category_id = $wp_query->get_queried_object()->term_id; $page_name = $wp_query->query['pagename']; $blog_url = get_permalink(get_option( 'page_for_posts' )); if ( is_category() ) { wp_redirect( get_category_link( $category_id ), '301' ); } if ( $page_name == 'blog' ) { wp_redirect( $blog_url, '301' ); } return false; } }@dcooney, does that make sense?
-
This reply was modified 9 years, 6 months ago by
The topic ‘Canonical URLs Causing Duplicate Content’ is closed to new replies.