Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I was trying to remove the rel=prev and rel=next tags from my website as my SEO gut suggested. I found those functions which perfectly do the magic:

remove_action('wp_head', 'start_post_rel_link', 10, 0 );
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);

however, after a while my SEO guy suggested to leave it on a categories section where over there it's necassary as far as SEO.

is there a simple way of implementing the rel=prev and rel=next tags only on a categories pages?, e.g: www.website.com/category/category-name and remove it from all other post types? (post, page, homepage etc etc)

Thanks, GIl

share|improve this question
add comment

3 Answers

Not entirely sure if I agree with the explanation of your SEO guy as rel=prev and rel=next are used for paginated archives.

Of course categories can be one, but also your blog if it'd contain multiple pages.

Anyways, here's what I'm currently using:

remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head' );

add_action( 'wp_head', 'cor_rel_next_prev_pagination' );
/**
 * Pagination with rel="next" and rel="prev".
 *
 * @link wp-includes|default-filters.php
 * @link http://core.trac.wordpress.org/ticket/18672 Implement rel="prev" and rel="next" for archives
 * @link http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html Pagination with rel="next" and rel="prev"
 */
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
  }
}

Edit: also I believe start_post_rel_link is no longer being used.

share|improve this answer
    
Hi Cor, I understand what you are saying and you are absolutely right, however in my case we don't have a blog and what happens is that we used many posts as a "static post" (we should have used pages instead but we didn't know) and they present a static content that has nothing to do with other posts, therefore it shouldn't have the "next" and "prev" tags which now exist and are bad for our SEO as Google refer to it as piece of content that it's part of more content. –  gil hamer Apr 2 '12 at 15:16
    
Does this code takes care of it?Does this code takes care of it? Thanks alot –  gil hamer Apr 2 '12 at 15:24
    
Hello @gilhamer, I understand. I can't promise you anything of course, but I'm pretty sure it'll work. (do check you site's source to be sure) –  Cor van Noorloos Apr 3 '12 at 6:28
    
Thanks, I will check it –  gil hamer Apr 4 '12 at 19:39
add comment

I think you can wrap your hooks into template_redirect hook, which is fired before sending content to browser, something like this:

add_action( 'template_redirect', 'wpse_47638_remove_rel_link' );
function wpse_47638_remove_rel_link() {
    if ( is_category() )
        return;
    remove_action('wp_head', 'start_post_rel_link', 10, 0 );
    remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
}
share|improve this answer
add comment

Try the is_category function. You should be able to add a high priority action to wp_head that checks the result, then conditionally runs the two statements you have above to remove the actions that assign REL to the links.

I'm honestly not sure if this method is operable this early in the WP lifecycle, but failing that, grab the URL using _SERVER and test for a category pattern.

share|improve this answer
    
Thanks charlie, I tried putting conditional statements in my functions.php but it didn't work –  gil hamer Apr 2 '12 at 15:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.