Using WordPress ‘previous_image_link()’ PHP function

The previous_image_link WordPress PHP function displays the previous image link that has the same post parent.

Usage

previous_image_link( $size, $text )

Example:

previous_image_link( 'thumbnail', '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: ‘thumbnail’.
    • $text (string|false|Optional) – Link text. Default: false.

More information

See WordPress Developer Resources: previous_image_link

 

Examples

Default Usage

Display the previous image link with default settings.

 

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

Choose a Recognized Image Size

Display the previous image link with different image sizes.

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

Define a Custom Image Size

Display the previous image link with a custom image size (37×37 pixels).

<?php previous_image_link( array( 37, 37 ) ); ?>

Display the previous image link using the image’s title value as the link text.

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

Display the previous image link with custom link text.

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