Using WordPress ‘prev_post_rel_link()’ PHP function

The prev_post_rel_link() WordPress PHP function displays the relational link for the previous post adjacent to the current post.

Usage

prev_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' );

Parameters

  • $title (string) – Optional. Link title format. Default is ‘%title’.
  • $in_same_term (bool) – Optional. Whether the link should be in the same taxonomy term. Default is false.
  • $excluded_terms (int[]|string) – Optional. Array or comma-separated list of excluded term IDs. Default is ”.
  • $taxonomy (string) – Optional. Taxonomy, if $in_same_term is true. Default is ‘category’.

More information

See WordPress Developer Resources: prev_post_rel_link

Examples

Display Previous Post Link with Default Settings

The following code displays the previous post link with default settings:

prev_post_rel_link();

Display Previous Post Link with Custom Title

The following code displays the previous post link with a custom title:

prev_post_rel_link('Previous: %title');

Display Previous Post Link in the Same Category

The following code displays the previous post link in the same category:

prev_post_rel_link('%title', true);

Display Previous Post Link Excluding Specific Terms

The following code displays the previous post link, excluding posts with term IDs 5 and 12:

prev_post_rel_link('%title', false, '5,12');

Display Previous Post Link in the Same Custom Taxonomy

The following code displays the previous post link in the same custom taxonomy called ‘genre’:

prev_post_rel_link('%title', true, '', 'genre');