Generating prev/next link-rel navigational elements

Published: On Monday, June 2, 2008

.[invalid] This feature got implemented with WP version 2.8 so information in this article isn't as useful as used to be, anymore…

I would guess this is thing that no template can provide yet: navigational link elements (always inside head part).

This code (working since version 2.5) inserts correctly filled link-s on singular (post/page) pages and on archive-type pages too.

<?php if (!is_singular()) { ?>
<link rel="prev" href="<?php echo get_previous_posts_page_link(); ?>" />
<link rel="next" href="<?php echo get_next_posts_page_link(); ?>" />
<?php } else {?>
<link rel="prev" href="<?php echo get_permalink(get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true)->ID); ?>" />
<link rel="next" href="<?php echo get_permalink(get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = false)->ID); ?>" />
<?php } ?>

What's this good for? It may bring some better understanding of website structure for search engines and it certainly brings usability/acces­sibility benefits for various apps, such as Opera browser. Why not to include this in the code of each site?


Comments

  1. 1.  Shaman wrote: On June 12., 2008 comment number 1

    Good idea, but it needs to fix outer situations like no existence of next post is.

  2. 2.  Kahi [author] wrote: On June 12., 2008 comment number 2

    ↪ Shaman, good note, you are right, I know about this issue. Unfortunately, the code is going to get more complicated. :-)

I quit working with WordPress, comments are closed. My plugins will not be updated any more – at least not by me. Feel free to modify my source codes though… Also I am not able to provide support, sorry. –Kahi