previous_image_link()WP 2.5.0

Outputs a link to the previous image attached to the post. Returns the HTML code of the link.

No Hooks.

Returns

null.

Usage

<?php previous_image_link( $size, $text ); ?>
$size(string/array)
Size of the image the link to which should be output. Can be: 'medium', 'large', 'fullsize'.
Default: 'thumbnail'
$text(string)
Link text (anchor).
Default: false

Examples

1

#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 7.0

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