adjacent_image_link

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

WordPress Version: 5.8

/**
 * Displays next or previous image link that has the same post parent.
 *
 * Retrieves the current attachment object from the $post global.
 *
 * @since 2.5.0
 *
 * @param bool         $prev Optional. Whether to display the next (false) or previous (true) link. Default true.
 * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array
 *                           of width and height values in pixels (in that order). Default 'thumbnail'.
 * @param bool         $text Optional. Link text. Default false.
 */
function adjacent_image_link($prev = true, $size = 'thumbnail', $text = false)
{
    echo get_adjacent_image_link($prev, $size, $text);
}

WordPress Version: 5.7

/**
 * Displays next or previous image link that has the same post parent.
 *
 * Retrieves the current attachment object from the $post global.
 *
 * @since 2.5.0
 *
 * @param bool         $prev Optional. Whether to display the next (false) or previous (true) link. Default true.
 * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array
 *                           of width and height values in pixels (in that order). Default 'thumbnail'.
 * @param bool         $text Optional. Link text. Default false.
 */
function adjacent_image_link($prev = true, $size = 'thumbnail', $text = false)
{
    $post = get_post();
    $attachments = array_values(get_children(array('post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID')));
    foreach ($attachments as $k => $attachment) {
        if ((int) $attachment->ID === (int) $post->ID) {
            break;
        }
    }
    $output = '';
    $attachment_id = 0;
    if ($attachments) {
        $k = $prev ? $k - 1 : ($k + 1);
        if (isset($attachments[$k])) {
            $attachment_id = $attachments[$k]->ID;
            $attr = array('alt' => get_the_title($attachment_id));
            $output = wp_get_attachment_link($attachment_id, $size, true, false, $text, $attr);
        }
    }
    $adjacent = $prev ? 'previous' : 'next';
    /**
     * Filters the adjacent image link.
     *
     * The dynamic portion of the hook name, `$adjacent`, refers to the type of adjacency,
     * either 'next', or 'previous'.
     *
     * @since 3.5.0
     *
     * @param string $output        Adjacent image HTML markup.
     * @param int    $attachment_id Attachment ID
     * @param string|int[] $size    Requested image size. Can be any registered image size name, or
     *                              an array of width and height values in pixels (in that order).
     * @param string $text          Link text.
     */
    echo apply_filters("{$adjacent}_image_link", $output, $attachment_id, $size, $text);
}

WordPress Version: 5.6

/**
 * Displays next or previous image link that has the same post parent.
 *
 * Retrieves the current attachment object from the $post global.
 *
 * @since 2.5.0
 *
 * @param bool         $prev Optional. Whether to display the next (false) or previous (true) link. Default true.
 * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array
 *                           of width and height values in pixels (in that order). Default 'thumbnail'.
 * @param bool         $text Optional. Link text. Default false.
 */
function adjacent_image_link($prev = true, $size = 'thumbnail', $text = false)
{
    $post = get_post();
    $attachments = array_values(get_children(array('post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID')));
    foreach ($attachments as $k => $attachment) {
        if ((int) $attachment->ID === (int) $post->ID) {
            break;
        }
    }
    $output = '';
    $attachment_id = 0;
    if ($attachments) {
        $k = $prev ? $k - 1 : ($k + 1);
        if (isset($attachments[$k])) {
            $attachment_id = $attachments[$k]->ID;
            $output = wp_get_attachment_link($attachment_id, $size, true, false, $text);
        }
    }
    $adjacent = $prev ? 'previous' : 'next';
    /**
     * Filters the adjacent image link.
     *
     * The dynamic portion of the hook name, `$adjacent`, refers to the type of adjacency,
     * either 'next', or 'previous'.
     *
     * @since 3.5.0
     *
     * @param string $output        Adjacent image HTML markup.
     * @param int    $attachment_id Attachment ID
     * @param string|int[] $size    Requested image size. Can be any registered image size name, or
     *                              an array of width and height values in pixels (in that order).
     * @param string $text          Link text.
     */
    echo apply_filters("{$adjacent}_image_link", $output, $attachment_id, $size, $text);
}

WordPress Version: 5.3

/**
 * Displays next or previous image link that has the same post parent.
 *
 * Retrieves the current attachment object from the $post global.
 *
 * @since 2.5.0
 *
 * @param bool         $prev Optional. Whether to display the next (false) or previous (true) link. Default true.
 * @param string|array $size Optional. Image size. Accepts any valid image size, or an array of width and height
 *                           values in pixels (in that order). Default 'thumbnail'.
 * @param bool         $text Optional. Link text. Default false.
 */
function adjacent_image_link($prev = true, $size = 'thumbnail', $text = false)
{
    $post = get_post();
    $attachments = array_values(get_children(array('post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID')));
    foreach ($attachments as $k => $attachment) {
        if (intval($attachment->ID) === intval($post->ID)) {
            break;
        }
    }
    $output = '';
    $attachment_id = 0;
    if ($attachments) {
        $k = $prev ? $k - 1 : ($k + 1);
        if (isset($attachments[$k])) {
            $attachment_id = $attachments[$k]->ID;
            $output = wp_get_attachment_link($attachment_id, $size, true, false, $text);
        }
    }
    $adjacent = $prev ? 'previous' : 'next';
    /**
     * Filters the adjacent image link.
     *
     * The dynamic portion of the hook name, `$adjacent`, refers to the type of adjacency,
     * either 'next', or 'previous'.
     *
     * @since 3.5.0
     *
     * @param string $output        Adjacent image HTML markup.
     * @param int    $attachment_id Attachment ID
     * @param string $size          Image size.
     * @param string $text          Link text.
     */
    echo apply_filters("{$adjacent}_image_link", $output, $attachment_id, $size, $text);
}

WordPress Version: 4.6

/**
 * Displays next or previous image link that has the same post parent.
 *
 * Retrieves the current attachment object from the $post global.
 *
 * @since 2.5.0
 *
 * @param bool         $prev Optional. Whether to display the next (false) or previous (true) link. Default true.
 * @param string|array $size Optional. Image size. Accepts any valid image size, or an array of width and height
 *                           values in pixels (in that order). Default 'thumbnail'.
 * @param bool         $text Optional. Link text. Default false.
 */
function adjacent_image_link($prev = true, $size = 'thumbnail', $text = false)
{
    $post = get_post();
    $attachments = array_values(get_children(array('post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID')));
    foreach ($attachments as $k => $attachment) {
        if ($attachment->ID == $post->ID) {
            break;
        }
    }
    $output = '';
    $attachment_id = 0;
    if ($attachments) {
        $k = $prev ? $k - 1 : ($k + 1);
        if (isset($attachments[$k])) {
            $attachment_id = $attachments[$k]->ID;
            $output = wp_get_attachment_link($attachment_id, $size, true, false, $text);
        }
    }
    $adjacent = $prev ? 'previous' : 'next';
    /**
     * Filters the adjacent image link.
     *
     * The dynamic portion of the hook name, `$adjacent`, refers to the type of adjacency,
     * either 'next', or 'previous'.
     *
     * @since 3.5.0
     *
     * @param string $output        Adjacent image HTML markup.
     * @param int    $attachment_id Attachment ID
     * @param string $size          Image size.
     * @param string $text          Link text.
     */
    echo apply_filters("{$adjacent}_image_link", $output, $attachment_id, $size, $text);
}

WordPress Version: 4.4

/**
 * Displays next or previous image link that has the same post parent.
 *
 * Retrieves the current attachment object from the $post global.
 *
 * @since 2.5.0
 *
 * @param bool         $prev Optional. Whether to display the next (false) or previous (true) link. Default true.
 * @param string|array $size Optional. Image size. Accepts any valid image size, or an array of width and height
 *                           values in pixels (in that order). Default 'thumbnail'.
 * @param bool         $text Optional. Link text. Default false.
 */
function adjacent_image_link($prev = true, $size = 'thumbnail', $text = false)
{
    $post = get_post();
    $attachments = array_values(get_children(array('post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID')));
    foreach ($attachments as $k => $attachment) {
        if ($attachment->ID == $post->ID) {
            break;
        }
    }
    $output = '';
    $attachment_id = 0;
    if ($attachments) {
        $k = $prev ? $k - 1 : ($k + 1);
        if (isset($attachments[$k])) {
            $attachment_id = $attachments[$k]->ID;
            $output = wp_get_attachment_link($attachment_id, $size, true, false, $text);
        }
    }
    $adjacent = $prev ? 'previous' : 'next';
    /**
     * Filter the adjacent image link.
     *
     * The dynamic portion of the hook name, `$adjacent`, refers to the type of adjacency,
     * either 'next', or 'previous'.
     *
     * @since 3.5.0
     *
     * @param string $output        Adjacent image HTML markup.
     * @param int    $attachment_id Attachment ID
     * @param string $size          Image size.
     * @param string $text          Link text.
     */
    echo apply_filters("{$adjacent}_image_link", $output, $attachment_id, $size, $text);
}

WordPress Version: 4.3

/**
 * Displays next or previous image link that has the same post parent.
 *
 * Retrieves the current attachment object from the $post global.
 *
 * @since 2.5.0
 *
 * @param bool         $prev Optional. Whether to display the next (false) or previous (true) link. Default true.
 * @param string|array $size Optional. Registered image size or flat array of height and width dimensions.
 *                                     Default 'thumbnail'.
 * @param bool         $text Optional. Link text. Default false.
 */
function adjacent_image_link($prev = true, $size = 'thumbnail', $text = false)
{
    $post = get_post();
    $attachments = array_values(get_children(array('post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID')));
    foreach ($attachments as $k => $attachment) {
        if ($attachment->ID == $post->ID) {
            break;
        }
    }
    $output = '';
    $attachment_id = 0;
    if ($attachments) {
        $k = $prev ? $k - 1 : ($k + 1);
        if (isset($attachments[$k])) {
            $attachment_id = $attachments[$k]->ID;
            $output = wp_get_attachment_link($attachment_id, $size, true, false, $text);
        }
    }
    $adjacent = $prev ? 'previous' : 'next';
    /**
     * Filter the adjacent image link.
     *
     * The dynamic portion of the hook name, `$adjacent`, refers to the type of adjacency,
     * either 'next', or 'previous'.
     *
     * @since 3.5.0
     *
     * @param string $output        Adjacent image HTML markup.
     * @param int    $attachment_id Attachment ID
     * @param string $size          Image size.
     * @param string $text          Link text.
     */
    echo apply_filters("{$adjacent}_image_link", $output, $attachment_id, $size, $text);
}

WordPress Version: 4.2

/**
 * Displays next or previous image link that has the same post parent.
 *
 * Retrieves the current attachment object from the $post global.
 *
 * @since 2.5.0
 *
 * @param bool         $prev Optional. Whether to display the next (false) or previous (true) link. Default true.
 * @param string|array $size Optional. Registered image size or flat array of height and width dimensions.
 *                                     Default 'thumbnail'.
 * @param bool         $text Optional. Link text. Default false.
 * @return string The adjacent image link.
 */
function adjacent_image_link($prev = true, $size = 'thumbnail', $text = false)
{
    $post = get_post();
    $attachments = array_values(get_children(array('post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID')));
    foreach ($attachments as $k => $attachment) {
        if ($attachment->ID == $post->ID) {
            break;
        }
    }
    $output = '';
    $attachment_id = 0;
    if ($attachments) {
        $k = $prev ? $k - 1 : ($k + 1);
        if (isset($attachments[$k])) {
            $attachment_id = $attachments[$k]->ID;
            $output = wp_get_attachment_link($attachment_id, $size, true, false, $text);
        }
    }
    $adjacent = $prev ? 'previous' : 'next';
    /**
     * Filter the adjacent image link.
     *
     * The dynamic portion of the hook name, `$adjacent`, refers to the type of adjacency,
     * either 'next', or 'previous'.
     *
     * @since 3.5.0
     *
     * @param string $output        Adjacent image HTML markup.
     * @param int    $attachment_id Attachment ID
     * @param string $size          Image size.
     * @param string $text          Link text.
     */
    echo apply_filters("{$adjacent}_image_link", $output, $attachment_id, $size, $text);
}

WordPress Version: 4.1

/**
 * Display next or previous image link that has the same post parent.
 *
 * Retrieves the current attachment object from the $post global.
 *
 * @since 2.5.0
 *
 * @param bool $prev Optional. Default is true to display previous link, false for next.
 */
function adjacent_image_link($prev = true, $size = 'thumbnail', $text = false)
{
    $post = get_post();
    $attachments = array_values(get_children(array('post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID')));
    foreach ($attachments as $k => $attachment) {
        if ($attachment->ID == $post->ID) {
            break;
        }
    }
    $output = '';
    $attachment_id = 0;
    if ($attachments) {
        $k = $prev ? $k - 1 : ($k + 1);
        if (isset($attachments[$k])) {
            $attachment_id = $attachments[$k]->ID;
            $output = wp_get_attachment_link($attachment_id, $size, true, false, $text);
        }
    }
    $adjacent = $prev ? 'previous' : 'next';
    /**
     * Filter the adjacent image link.
     *
     * The dynamic portion of the hook name, `$adjacent`, refers to the type of adjacency,
     * either 'next', or 'previous'.
     *
     * @since 3.5.0
     *
     * @param string $output        Adjacent image HTML markup.
     * @param int    $attachment_id Attachment ID
     * @param string $size          Image size.
     * @param string $text          Link text.
     */
    echo apply_filters("{$adjacent}_image_link", $output, $attachment_id, $size, $text);
}

WordPress Version: 4.0

/**
 * Display next or previous image link that has the same post parent.
 *
 * Retrieves the current attachment object from the $post global.
 *
 * @since 2.5.0
 *
 * @param bool $prev Optional. Default is true to display previous link, false for next.
 */
function adjacent_image_link($prev = true, $size = 'thumbnail', $text = false)
{
    $post = get_post();
    $attachments = array_values(get_children(array('post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID')));
    foreach ($attachments as $k => $attachment) {
        if ($attachment->ID == $post->ID) {
            break;
        }
    }
    $output = '';
    $attachment_id = 0;
    if ($attachments) {
        $k = $prev ? $k - 1 : ($k + 1);
        if (isset($attachments[$k])) {
            $attachment_id = $attachments[$k]->ID;
            $output = wp_get_attachment_link($attachment_id, $size, true, false, $text);
        }
    }
    $adjacent = $prev ? 'previous' : 'next';
    /**
     * Filter the adjacent image link.
     *
     * The dynamic portion of the hook name, $adjacent, refers to the type of adjacency,
     * either 'next', or 'previous'.
     *
     * @since 3.5.0
     *
     * @param string $output        Adjacent image HTML markup.
     * @param int    $attachment_id Attachment ID
     * @param string $size          Image size.
     * @param string $text          Link text.
     */
    echo apply_filters("{$adjacent}_image_link", $output, $attachment_id, $size, $text);
}

WordPress Version: 3.9

/**
 * Display next or previous image link that has the same post parent.
 *
 * Retrieves the current attachment object from the $post global.
 *
 * @since 2.5.0
 *
 * @param bool $prev Optional. Default is true to display previous link, false for next.
 */
function adjacent_image_link($prev = true, $size = 'thumbnail', $text = false)
{
    $post = get_post();
    $attachments = array_values(get_children(array('post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID')));
    foreach ($attachments as $k => $attachment) {
        if ($attachment->ID == $post->ID) {
            break;
        }
    }
    $k = $prev ? $k - 1 : ($k + 1);
    $output = $attachment_id = null;
    if (isset($attachments[$k])) {
        $attachment_id = $attachments[$k]->ID;
        $output = wp_get_attachment_link($attachment_id, $size, true, false, $text);
    }
    $adjacent = $prev ? 'previous' : 'next';
    /**
     * Filter the adjacent image link.
     *
     * The dynamic portion of the hook name, $adjacent, refers to the type of adjacency,
     * either 'next', or 'previous'.
     *
     * @since 3.5.0
     *
     * @param string $output        Adjacent image HTML markup.
     * @param int    $attachment_id Attachment ID
     * @param string $size          Image size.
     * @param string $text          Link text.
     */
    echo apply_filters("{$adjacent}_image_link", $output, $attachment_id, $size, $text);
}

WordPress Version: 3.7

/**
 * Display next or previous image link that has the same post parent.
 *
 * Retrieves the current attachment object from the $post global.
 *
 * @since 2.5.0
 *
 * @param bool $prev Optional. Default is true to display previous link, false for next.
 */
function adjacent_image_link($prev = true, $size = 'thumbnail', $text = false)
{
    $post = get_post();
    $attachments = array_values(get_children(array('post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID')));
    foreach ($attachments as $k => $attachment) {
        if ($attachment->ID == $post->ID) {
            break;
        }
    }
    $k = $prev ? $k - 1 : ($k + 1);
    $output = $attachment_id = null;
    if (isset($attachments[$k])) {
        $attachment_id = $attachments[$k]->ID;
        $output = wp_get_attachment_link($attachment_id, $size, true, false, $text);
    }
    $adjacent = $prev ? 'previous' : 'next';
    echo apply_filters("{$adjacent}_image_link", $output, $attachment_id, $size, $text);
}