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
Display previous image link with default size and text
This example displays the previous image link with the default ‘thumbnail’ size and ‘Previous Image’ as the link text.
echo get_previous_image_link();
Display previous image link with custom size and text
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');
Display previous image link with custom dimensions and text
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');
Display previous image link with no link text
This example displays the previous image link with the ‘large’ size and no link text.
echo get_previous_image_link('large', false);
Display previous image link and wrap it in a div
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>';