Support » Themes and Templates » Removing rel=next / rel=prev on next / previous links

  • Hi I’m trying to remove the rel=prev and rel=next on the next post and previous post links. I have googled and found ways to remove it from the header but that is not what I want to do.

    From the single.php template the portion of code that is next_post_link which calls adjacent_post_link

    It seems that rel= next and rel=previous is hard coded into that function.

    Is there a way to remove it without actually editing the code in link-template.php?

    I’m not even sure that is exactly the code I want now that I take a second look.

    Here is the website:

    Under the photos there is a link to the next and previous article. Within those links there is a rel= and we want to remove that.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Not sure why you would want to remove these. They are not visible to users, and they help search engines determine where links are in a series (more info here).

    It looks like you’ve already removed them, as I don’t see them on the site now. Removing from link-template.php would be a bad idea, as edited core files will just be overwritten when you next update.

    Yes I removed them from the core file just as a temporary fix until I can find out how to remove the properly if possible…

    I suppose I could write a custom function that redefines the core function?

    I don’t know why we want to remove them. Our SEO expert seems to think they are bad for google, because google uses the rel fields in the header.


    But if you want to remove them, there are filters for previous_post_rel_link and next_post_rel_link; you could use a regex to yank them out (and not have to modify Core).

    Regexp is a good idea iculd just do it in the template by getting the link and changing the output.

    Im not sure how one could do this with a filter, if you have an example that would be great. I never really got my head around the filters.

    function slug_remove_rel_prev( $format ) {
    	return str_replace( ' rel="prev"', '', $format );
    add_filter( 'previous_post_link', 'slug_remove_rel_prev' );

    Duplicate and change accordingly for “next”. That’s two single quotes after “prev”, not a single double quote.

    Still don’t understand why, but there ya go 🙂

    Oh now i understand the filter, it runs a function with the result from the previous!


    Indeed, the magical way to safely modify core behaviour:

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Removing rel=next / rel=prev on next / previous links’ is closed to new replies.