Skip to content

Instantly share code, notes, and snippets.

@singpolyma
Created May 30, 2009 18:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save singpolyma/120586 to your computer and use it in GitHub Desktop.
Save singpolyma/120586 to your computer and use it in GitHub Desktop.
--- link-template.php 2009-01-24 01:33:37.000000000 -0800
+++ link-template.php 2009-05-30 11:10:41.000000000 -0700
@@ -950,6 +950,9 @@
else
$post = get_adjacent_post($in_same_cat, $excluded_categories, $previous);
+ $rel = 'next';
+ if($previous) $rel = 'prev';
+
if ( !$post )
return;
@@ -961,7 +964,7 @@
$title = apply_filters('the_title', $title, $post);
$date = mysql2date(get_option('date_format'), $post->post_date);
- $string = '<a href="'.get_permalink($post).'">';
+ $string = '<a rel="'.$rel.'" href="'.get_permalink($post).'">';
$link = str_replace('%title', $title, $link);
$link = str_replace('%date', $date, $link);
$link = $string . $link . '</a>';
<?php
/*
Plugin Name: rel=prev/next
Plugin URI: http://singpolyma.net/plugins/
Description: Adds rel/prev/next to next/previous posts links
Version: 0.1
Author: Stephen Paul Weber
Author URI: http://singpolyma.net
License: MIT license (http://www.opensource.org/licenses/mit-license.php)
*/
add_filter('next_posts_link_attributes', 'get_next_posts_link_attributes');
add_filter('previous_posts_link_attributes', 'get_previous_posts_link_attributes');
if (!function_exists('get_next_posts_link_attributes')){
function get_next_posts_link_attributes($attr){
$attr .= 'rel="prev"';
return $attr;
}
}
if (!function_exists('get_previous_posts_link_attributes')){
function get_previous_posts_link_attributes($attr){
$attr .= 'rel="next"';
return $attr;
}
}
?>
@dumann78
Copy link

Thats work, nice but need to little change 'rel="prev"'; to 'rel="next"';

if (!function_exists('get_next_posts_link_attributes')){
	function get_next_posts_link_attributes($attr){
		$attr .= 'rel="prev"';
		return $attr;
	}
}
if (!function_exists('get_previous_posts_link_attributes')){
	function get_previous_posts_link_attributes($attr){
		$attr .= 'rel="next"';
		return $attr;
	}
}

to

if (!function_exists('get_next_posts_link_attributes')){
	function get_next_posts_link_attributes($attr){
		$attr .= 'rel="next"';
		return $attr;
	}
}
if (!function_exists('get_previous_posts_link_attributes')){
	function get_previous_posts_link_attributes($attr){
		$attr .= 'rel="prev"';
		return $attr;
	}
}

use it on www.whatisthewik.com and work, thanks singpolyma

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment