previous_image_link()WP 2.5.0

Displays previous image link that has the same post parent.

No Hooks.

Return

null. Nothing (null).

Usage

previous_image_link( $size, $text );
$size(string|int[])
Image size. Accepts any registered image size name, or an array of width and height values in pixels (in that order).
Default: 'thumbnail'
$text(string|false)
Link text.
Default: false

Examples

0

#1 Basic Examples

Default Usage

<?php previous_image_link(); ?>

Working example

<div class="alignleft"><?php previous_image_link(); ?></div>
0

#2 Selecting pictures of a certain size

<?php previous_image_link( 'thumbnail' ); ?>
<?php previous_image_link( 'medium' ); ?>
<?php previous_image_link( 'large' ); ?>
<?php previous_image_link( 'fullsize' ); ?>
0

#3 Defining custom image size

<?php previous_image_link( [ 50, 50 ] ); ?>

Keep in mind that if you specify a custom size, the picture will not be actually resized. The size will be set in the code and the browser will reduce/increase the original size by stretching or compressing the original image.

0

#4 The title of the image as the text of the link

To do this, define the first argument as false or 0.

<?php previous_image_link( false ); ?>
<?php previous_image_link( 0 ); ?>
0

#5 Custom text as link text

To do this, set the first parameter to false and in the second parameter specify the desired link text, for example 'Previous picture':

<?php previous_image_link( false, 'Previous picture' ); ?>

Changelog

Since 2.5.0 Introduced.

previous_image_link() code WP 6.6.2

function previous_image_link( $size = 'thumbnail', $text = false ) {
	echo get_previous_image_link( $size, $text );
}