The next_post_rel_link() WordPress PHP function is used to display the relational link for the next post that is adjacent to the current post.
Table of contents
Usage
Let’s say you want to display a link to the next post in the same category, ignoring posts in category ID 10:
next_post_rel_link('%title', true, '10', 'category');
This will output something like:
<link rel="next" title="Title of Next Post" href="http://yourwebsite.com/next-post/">
Parameters
$title(string, optional): Link title format. The default value is ‘%title’.$in_same_term(bool, optional): Whether link should be in the same taxonomy term. The default value is false.$excluded_terms(int | string, optional): Array or comma-separated list of excluded term IDs. The default value is ”.$taxonomy(string, optional): Taxonomy, if$in_same_termis true. The default value is ‘category’.
More information
See WordPress Developer Resources: next_post_rel_link()
This function is part of WordPress core and is typically used in themes for navigation between posts. It is not deprecated and can be found in the wp-includes/link-template.php file.
Examples
Basic Usage
Display a simple next post relational link.
next_post_rel_link();
This will output a relational link to the next post adjacent to the current one.
Link with Custom Title
Display a link with a custom title format.
next_post_rel_link('Next post: %title');
This will output a relational link to the next post with a title that reads “Next post: [post title]”.
Link within Same Category
Display a link to the next post within the same category.
next_post_rel_link('%title', true);
This will output a relational link to the next post in the same category.
Link Excluding Certain Categories
Display a link to the next post, excluding posts from certain categories.
next_post_rel_link('%title', false, '10,15');
This will output a relational link to the next post, skipping posts in categories with IDs 10 and 15.
Link within a Custom Taxonomy
Display a link to the next post within the same custom taxonomy.
next_post_rel_link('%title', true, '', 'product_cat');
This will output a relational link to the next post in the same custom taxonomy ‘product_cat’.