get_adjacent_post_rel_link

The timeline below displays how wordpress function get_adjacent_post_rel_link has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.2

/**
 * Retrieves the adjacent post relational link.
 *
 * Can either be next or previous post relational link.
 *
 * @since 2.8.0
 *
 * @param string       $title          Optional. Link title format. Default '%title'.
 * @param bool         $in_same_term   Optional. Whether link should be in the same taxonomy term.
 *                                     Default false.
 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
 *                                     Default empty.
 * @param bool         $previous       Optional. Whether to display link to previous or next post.
 *                                     Default true.
 * @param string       $taxonomy       Optional. Taxonomy, if `$in_same_term` is true. Default 'category'.
 * @return string|void The adjacent post relational link URL.
 */
function get_adjacent_post_rel_link($title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category')
{
    $post = get_post();
    if ($previous && is_attachment() && $post) {
        $post = get_post($post->post_parent);
    } else {
        $post = get_adjacent_post($in_same_term, $excluded_terms, $previous, $taxonomy);
    }
    if (empty($post)) {
        return;
    }
    $post_title = the_title_attribute(array('echo' => false, 'post' => $post));
    if (empty($post_title)) {
        $post_title = $previous ? __('Previous Post') : __('Next Post');
    }
    $date = mysql2date(get_option('date_format'), $post->post_date);
    $title = str_replace('%title', $post_title, $title);
    $title = str_replace('%date', $date, $title);
    $link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";
    $link .= esc_attr($title);
    $link .= "' href='" . get_permalink($post) . "' />\n";
    $adjacent = $previous ? 'previous' : 'next';
    /**
     * Filters the adjacent post relational link.
     *
     * The dynamic portion of the hook name, `$adjacent`, refers to the type
     * of adjacency, 'next' or 'previous'.
     *
     * Possible hook names include:
     *
     *  - `next_post_rel_link`
     *  - `previous_post_rel_link`
     *
     * @since 2.8.0
     *
     * @param string $link The relational link.
     */
    return apply_filters("{$adjacent}_post_rel_link", $link);
}

WordPress Version: 5.8

/**
 * Retrieves the adjacent post relational link.
 *
 * Can either be next or previous post relational link.
 *
 * @since 2.8.0
 *
 * @param string       $title          Optional. Link title format. Default '%title'.
 * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
 * @param bool         $previous       Optional. Whether to display link to previous or next post. Default true.
 * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
 * @return string|void The adjacent post relational link URL.
 */
function get_adjacent_post_rel_link($title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category')
{
    $post = get_post();
    if ($previous && is_attachment() && $post) {
        $post = get_post($post->post_parent);
    } else {
        $post = get_adjacent_post($in_same_term, $excluded_terms, $previous, $taxonomy);
    }
    if (empty($post)) {
        return;
    }
    $post_title = the_title_attribute(array('echo' => false, 'post' => $post));
    if (empty($post_title)) {
        $post_title = $previous ? __('Previous Post') : __('Next Post');
    }
    $date = mysql2date(get_option('date_format'), $post->post_date);
    $title = str_replace('%title', $post_title, $title);
    $title = str_replace('%date', $date, $title);
    $link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";
    $link .= esc_attr($title);
    $link .= "' href='" . get_permalink($post) . "' />\n";
    $adjacent = $previous ? 'previous' : 'next';
    /**
     * Filters the adjacent post relational link.
     *
     * The dynamic portion of the hook name, `$adjacent`, refers to the type
     * of adjacency, 'next' or 'previous'.
     *
     * Possible hook names include:
     *
     *  - `next_post_rel_link`
     *  - `previous_post_rel_link`
     *
     * @since 2.8.0
     *
     * @param string $link The relational link.
     */
    return apply_filters("{$adjacent}_post_rel_link", $link);
}

WordPress Version: 5.7

/**
 * Retrieves the adjacent post relational link.
 *
 * Can either be next or previous post relational link.
 *
 * @since 2.8.0
 *
 * @param string       $title          Optional. Link title format. Default '%title'.
 * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
 * @param bool         $previous       Optional. Whether to display link to previous or next post. Default true.
 * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
 * @return string|void The adjacent post relational link URL.
 */
function get_adjacent_post_rel_link($title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category')
{
    $post = get_post();
    if ($previous && is_attachment() && $post) {
        $post = get_post($post->post_parent);
    } else {
        $post = get_adjacent_post($in_same_term, $excluded_terms, $previous, $taxonomy);
    }
    if (empty($post)) {
        return;
    }
    $post_title = the_title_attribute(array('echo' => false, 'post' => $post));
    if (empty($post_title)) {
        $post_title = $previous ? __('Previous Post') : __('Next Post');
    }
    $date = mysql2date(get_option('date_format'), $post->post_date);
    $title = str_replace('%title', $post_title, $title);
    $title = str_replace('%date', $date, $title);
    $link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";
    $link .= esc_attr($title);
    $link .= "' href='" . get_permalink($post) . "' />\n";
    $adjacent = $previous ? 'previous' : 'next';
    /**
     * Filters the adjacent post relational link.
     *
     * The dynamic portion of the hook name, `$adjacent`, refers to the type
     * of adjacency, 'next' or 'previous'.
     *
     * @since 2.8.0
     *
     * @param string $link The relational link.
     */
    return apply_filters("{$adjacent}_post_rel_link", $link);
}

WordPress Version: 5.3

/**
 * Retrieves the adjacent post relational link.
 *
 * Can either be next or previous post relational link.
 *
 * @since 2.8.0
 *
 * @param string       $title          Optional. Link title format. Default '%title'.
 * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
 * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
 * @param bool         $previous       Optional. Whether to display link to previous or next post. Default true.
 * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
 * @return string|void The adjacent post relational link URL.
 */
function get_adjacent_post_rel_link($title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category')
{
    $post = get_post();
    if ($previous && is_attachment() && $post) {
        $post = get_post($post->post_parent);
    } else {
        $post = get_adjacent_post($in_same_term, $excluded_terms, $previous, $taxonomy);
    }
    if (empty($post)) {
        return;
    }
    $post_title = the_title_attribute(array('echo' => false, 'post' => $post));
    if (empty($post_title)) {
        $post_title = $previous ? __('Previous Post') : __('Next Post');
    }
    $date = mysql2date(get_option('date_format'), $post->post_date);
    $title = str_replace('%title', $post_title, $title);
    $title = str_replace('%date', $date, $title);
    $link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";
    $link .= esc_attr($title);
    $link .= "' href='" . get_permalink($post) . "' />\n";
    $adjacent = $previous ? 'previous' : 'next';
    /**
     * Filters the adjacent post relational link.
     *
     * The dynamic portion of the hook name, `$adjacent`, refers to the type
     * of adjacency, 'next' or 'previous'.
     *
     * @since 2.8.0
     *
     * @param string $link The relational link.
     */
    return apply_filters("{$adjacent}_post_rel_link", $link);
}

WordPress Version: 4.6

/**
 * Retrieves the adjacent post relational link.
 *
 * Can either be next or previous post relational link.
 *
 * @since 2.8.0
 *
 * @param string       $title          Optional. Link title format. Default '%title'.
 * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
 * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
 * @param bool         $previous       Optional. Whether to display link to previous or next post. Default true.
 * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
 * @return string|void The adjacent post relational link URL.
 */
function get_adjacent_post_rel_link($title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category')
{
    if ($previous && is_attachment() && $post = get_post()) {
        $post = get_post($post->post_parent);
    } else {
        $post = get_adjacent_post($in_same_term, $excluded_terms, $previous, $taxonomy);
    }
    if (empty($post)) {
        return;
    }
    $post_title = the_title_attribute(array('echo' => false, 'post' => $post));
    if (empty($post_title)) {
        $post_title = $previous ? __('Previous Post') : __('Next Post');
    }
    $date = mysql2date(get_option('date_format'), $post->post_date);
    $title = str_replace('%title', $post_title, $title);
    $title = str_replace('%date', $date, $title);
    $link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";
    $link .= esc_attr($title);
    $link .= "' href='" . get_permalink($post) . "' />\n";
    $adjacent = $previous ? 'previous' : 'next';
    /**
     * Filters the adjacent post relational link.
     *
     * The dynamic portion of the hook name, `$adjacent`, refers to the type
     * of adjacency, 'next' or 'previous'.
     *
     * @since 2.8.0
     *
     * @param string $link The relational link.
     */
    return apply_filters("{$adjacent}_post_rel_link", $link);
}

WordPress Version: 4.3

/**
 * Get adjacent post relational link.
 *
 * Can either be next or previous post relational link.
 *
 * @since 2.8.0
 *
 * @param string       $title          Optional. Link title format.
 * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term.
 * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
 * @param bool         $previous       Optional. Whether to display link to previous or next post. Default true.
 * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
 * @return string|void The adjacent post relational link URL.
 */
function get_adjacent_post_rel_link($title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category')
{
    if ($previous && is_attachment() && $post = get_post()) {
        $post = get_post($post->post_parent);
    } else {
        $post = get_adjacent_post($in_same_term, $excluded_terms, $previous, $taxonomy);
    }
    if (empty($post)) {
        return;
    }
    $post_title = the_title_attribute(array('echo' => false, 'post' => $post));
    if (empty($post_title)) {
        $post_title = $previous ? __('Previous Post') : __('Next Post');
    }
    $date = mysql2date(get_option('date_format'), $post->post_date);
    $title = str_replace('%title', $post_title, $title);
    $title = str_replace('%date', $date, $title);
    $link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";
    $link .= esc_attr($title);
    $link .= "' href='" . get_permalink($post) . "' />\n";
    $adjacent = $previous ? 'previous' : 'next';
    /**
     * Filter the adjacent post relational link.
     *
     * The dynamic portion of the hook name, `$adjacent`, refers to the type
     * of adjacency, 'next' or 'previous'.
     *
     * @since 2.8.0
     *
     * @param string $link The relational link.
     */
    return apply_filters("{$adjacent}_post_rel_link", $link);
}

WordPress Version: 4.1

/**
 * Get adjacent post relational link.
 *
 * Can either be next or previous post relational link.
 *
 * @since 2.8.0
 *
 * @param string       $title          Optional. Link title format.
 * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term.
 * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
 * @param bool         $previous       Optional. Whether to display link to previous or next post. Default true.
 * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
 * @return string The adjacent post relational link URL.
 */
function get_adjacent_post_rel_link($title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category')
{
    if ($previous && is_attachment() && $post = get_post()) {
        $post = get_post($post->post_parent);
    } else {
        $post = get_adjacent_post($in_same_term, $excluded_terms, $previous, $taxonomy);
    }
    if (empty($post)) {
        return;
    }
    $post_title = the_title_attribute(array('echo' => false, 'post' => $post));
    if (empty($post_title)) {
        $post_title = $previous ? __('Previous Post') : __('Next Post');
    }
    $date = mysql2date(get_option('date_format'), $post->post_date);
    $title = str_replace('%title', $post_title, $title);
    $title = str_replace('%date', $date, $title);
    $link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";
    $link .= esc_attr($title);
    $link .= "' href='" . get_permalink($post) . "' />\n";
    $adjacent = $previous ? 'previous' : 'next';
    /**
     * Filter the adjacent post relational link.
     *
     * The dynamic portion of the hook name, `$adjacent`, refers to the type
     * of adjacency, 'next' or 'previous'.
     *
     * @since 2.8.0
     *
     * @param string $link The relational link.
     */
    return apply_filters("{$adjacent}_post_rel_link", $link);
}

WordPress Version: 3.9

/**
 * Get adjacent post relational link.
 *
 * Can either be next or previous post relational link.
 *
 * @since 2.8.0
 *
 * @param string       $title          Optional. Link title format.
 * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term.
 * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
 * @param bool         $previous       Optional. Whether to display link to previous or next post. Default true.
 * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
 * @return string
 */
function get_adjacent_post_rel_link($title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category')
{
    if ($previous && is_attachment() && $post = get_post()) {
        $post = get_post($post->post_parent);
    } else {
        $post = get_adjacent_post($in_same_term, $excluded_terms, $previous, $taxonomy);
    }
    if (empty($post)) {
        return;
    }
    $post_title = the_title_attribute(array('echo' => false, 'post' => $post));
    if (empty($post_title)) {
        $post_title = $previous ? __('Previous Post') : __('Next Post');
    }
    $date = mysql2date(get_option('date_format'), $post->post_date);
    $title = str_replace('%title', $post_title, $title);
    $title = str_replace('%date', $date, $title);
    $link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";
    $link .= esc_attr($title);
    $link .= "' href='" . get_permalink($post) . "' />\n";
    $adjacent = $previous ? 'previous' : 'next';
    /**
     * Filter the adjacent post relational link.
     *
     * The dynamic portion of the hook name, $adjacent, refers to the type
     * of adjacency, 'next' or 'previous'.
     *
     * @since 2.8.0
     *
     * @param string $link The relational link.
     */
    return apply_filters("{$adjacent}_post_rel_link", $link);
}

WordPress Version: 3.8

/**
 * Get adjacent post relational link.
 *
 * Can either be next or previous post relational link.
 *
 * @since 2.8.0
 *
 * @param string       $title          Optional. Link title format.
 * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term.
 * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
 * @param bool         $previous       Optional. Whether to display link to previous or next post. Default true.
 * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
 * @return string
 */
function get_adjacent_post_rel_link($title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category')
{
    if ($previous && is_attachment() && $post = get_post()) {
        $post = get_post($post->post_parent);
    } else {
        $post = get_adjacent_post($in_same_term, $excluded_terms, $previous, $taxonomy);
    }
    if (empty($post)) {
        return;
    }
    $post_title = the_title_attribute(array('echo' => false, 'post' => $post));
    if (empty($post_title)) {
        $post_title = $previous ? __('Previous Post') : __('Next Post');
    }
    $date = mysql2date(get_option('date_format'), $post->post_date);
    $title = str_replace('%title', $post_title, $title);
    $title = str_replace('%date', $date, $title);
    $link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";
    $link .= esc_attr($title);
    $link .= "' href='" . get_permalink($post) . "' />\n";
    $adjacent = $previous ? 'previous' : 'next';
    return apply_filters("{$adjacent}_post_rel_link", $link);
}

WordPress Version: 3.7

/**
 * Get adjacent post relational link.
 *
 * Can either be next or previous post relational link.
 *
 * @since 2.8.0
 *
 * @param string $title Optional. Link title format.
 * @param bool $in_same_cat Optional. Whether link should be in a same category.
 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
 * @param bool $previous Optional, default is true. Whether to display link to previous or next post.
 * @return string
 */
function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true)
{
    if ($previous && is_attachment() && $post = get_post()) {
        $post = get_post($post->post_parent);
    } else {
        $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous);
    }
    if (empty($post)) {
        return;
    }
    $post_title = the_title_attribute(array('echo' => false, 'post' => $post));
    if (empty($post_title)) {
        $post_title = $previous ? __('Previous Post') : __('Next Post');
    }
    $date = mysql2date(get_option('date_format'), $post->post_date);
    $title = str_replace('%title', $post_title, $title);
    $title = str_replace('%date', $date, $title);
    $link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";
    $link .= esc_attr($title);
    $link .= "' href='" . get_permalink($post) . "' />\n";
    $adjacent = $previous ? 'previous' : 'next';
    return apply_filters("{$adjacent}_post_rel_link", $link);
}