Using WordPress ‘get_previous_image_link()’ PHP function

The get_previous_image_link() WordPress PHP function retrieves the previous image link that has the same post parent.

Usage

get_previous_image_link($size, $text);

Example:

echo get_previous_image_link('medium', 'Previous Image');

Parameters

  • $size (string|int, Optional) – Image size. Accepts any registered image size name, or an array of width and height values in pixels (in that order). Default is ‘thumbnail’.
  • $text (string|false, Optional) – Link text. Default is false.

More information

See WordPress Developer Resources: get_previous_image_link()

Examples

This example displays the previous image link with the default ‘thumbnail’ size and ‘Previous Image’ as the link text.

echo get_previous_image_link();

This example displays the previous image link with the ‘medium’ size and ‘Previous Photo’ as the link text.

echo get_previous_image_link('medium', 'Previous Photo');

This example displays the previous image link with custom dimensions of 200×200 pixels and ‘Previous Picture’ as the link text.

echo get_previous_image_link(array(200, 200), 'Previous Picture');

This example displays the previous image link with the ‘large’ size and no link text.

echo get_previous_image_link('large', false);

This example displays the previous image link with the ‘medium’ size and ‘Previous’ as the link text, wrapped in a <div> with a custom class.

echo '<div class="previous-image-link">';
echo get_previous_image_link('medium', 'Previous');
echo '</div>';