WordPress.org

Ready to get started?Download WordPress

Forums

Removing rel=next / rel=prev on next / previous links (8 posts)

  1. jamesbe
    Member
    Posted 1 year ago #

    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:
    http://www.autos.ca/first-drives/first-drive-2013-chevrolet-malibu/

    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.

  2. Kirk Wight
    Member
    Posted 1 year ago #

    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.

  3. jamesbe
    Member
    Posted 1 year ago #

    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.

  4. Kirk Wight
    Member
    Posted 1 year ago #

    Odd.

    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).

  5. jamesbe
    Member
    Posted 1 year ago #

    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.

  6. Kirk Wight
    Member
    Posted 1 year ago #

    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 :)

  7. jamesbe
    Member
    Posted 1 year ago #

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

    Thanks.

  8. Kirk Wight
    Member
    Posted 1 year ago #

    Indeed, the magical way to safely modify core behaviour:

    http://codex.wordpress.org/Plugin_API/Filter_Reference

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.