previous_image_link()WP 2.5.0

Displays previous image link that has the same post parent.

No Hooks.


null. Ничего (null).


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



#1 Basic Examples

Default Usage

<?php previous_image_link(); ?>

Working example

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

#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' ); ?>

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


#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 ); ?>

#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' ); ?>


Since 2.5.0 Introduced.

previous_image_link() code WP 6.4.1

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