Tutorial: How to Remove link rel=’prev’ and link rel=’next’ from WordPress Head
How to Remove link rel=’prev’ and link rel=’next’ from WordPress Head (in WP 3.0+)
WordPress, in its default state, prints a lot of excess code to the head section of webpages. One element that always annoyed me were two entries that always appeared:
<link rel='prev' title='' href='' /> <link rel='next' title='' href='' />
These entries are recommended for web usability for disabled persons–consider that before removing them. We were looking for a way to lean up our pages, though, so we thought we’d like to remove these entries. There are some outdated instructions in WP forums that will not work in WP 3.0; we tried several approaches, but nothing worked.
In your WordPress template, you’ll find your functions.php file. Open that file and enter the following line.
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
This “filter,” as it is called, will tell WordPress not to generate the link rel=’prev’ and link rel=’next’ lines in the WordPress head.
Just a note on why those outdated instructions wouldn’t work with WP 3.0. The filter we created instructs WP to turn off the action titled “adjacent_posts_rel_link_wp_head.” Our commands works in WP 3.0 and above because the former action prior to 3.0 was titled “adjacent_posts_rel_link.”
I put your code on my function.php
but it did not work
help me
Dennis
Well, If you aren’t running WP 3.0 or above, my code won’t work. In the last paragraph it describes the use of remove_action( ‘wp_head’, ‘adjacent_posts_rel_link’, 10, 0 ); instead…give that a try.
try this
add_filter( ‘wpseo_next_rel_link’, ‘__return_false’ );
add_filter( ‘wpseo_prev_rel_link’, ‘__return_false’ );
Thanks, works like a charm!
Thank you, thank you, thank you…!!! You a) answered a question I’ve been asking myself everytime I looked at my server logs, and b) told me how to eliminate the problem. I just didn’t understand where all those referrers to an actually totally unimportant rant I wrote came from; the post I wrote before seems to have turned into the most popular Google search result of my blog, so there were a lot of those, and I just couldn’t find it anywhere on the page until just now when I looked at the source code of the rendered page. A somewhat unexpected cause; especially since I have a hard time seeing the point of this WP function. What good does it do if there is no visible link on the page? Anyway, thanks for posting, big help!
Worked great for me! just what I needed!
Worked perfectly! Thank you for the tip :)
Worked Like Charm :) Thank you
Hey,
Thanks for your Code, unfortunately it doesn’t work in WordPress 3.4.1 .
Regards
Dang, we’ll have to update this post when we get a chance, thank’s for the head’s up
Works perfectly with WP3.4.2
Thanks!
Hi Michael David,
perfekt, vielen Dank für deinen Code Schnipsel, der hat mir noch gefehlt.
Gruß
Helmut
My German isn’t great, but since see “perfect” and “dank” I take it that this worked for you.
Worked perfect in my WP 3.4.2.
I hate that ‘extra’ code that is always getting added by default. Many thanks!
Thanks for this filter.
Tested and work with WP 3.5.
Worked on perfect on one of my sites. Thanks!
Thanks you so much!
Thanks, it works
Thank you very much!
It works , Thanks for sharing it.
Hi Michael
Just tried your code and it worked perfectly.
it is simpler than another function I had before
Thanks for sharing!
Thanks,
It work in WordPress 3.5.2.
thanks for the trick ! it’s work
I need to modify in ftp because WP don’t allow any modification.
Thanks lot