WordPress next_image_link() Function

Beginner
6 min read
Updated: Nov 2026
3 examples
Prints a link

Definition

In WordPress, next_image_link() prints a link to the next image in the same post. It is used on an image attachment page so visitors can move through a gallery.

You can show a thumbnail (default) or your own text.

Syntax

A few ways to call next_image_link().

WordPress
<?php
next_image_link( 'thumbnail', 'Next image' );
CallWhat it does
next_image_link()Link shown as a thumbnail of the next image.
next_image_link( 'medium' )Link shown as a medium-size image.
next_image_link( false, 'Next image &raquo;' )Link shown as text.
previous_image_link()The same, for the previous image.

It prints the link. If there is no next image, nothing is printed.

Full declaration
WordPress
next_image_link( string|int[] $size = 'thumbnail', string|false $text = false ): void

Parameters

ParameterDescription
$sizestring|int[]. The image size for the thumbnail link, such as thumbnail or medium. Default is thumbnail.
$textstring|false. Link text. If false, the image itself is used. Default is false.

Return Value

Return ValueDescription
voidNothing is returned. The link is printed.

WordPress Examples

Three short examples. Each one shows the code and what it prints.

Example 1 — Show a text link

Print a simple Next image link.

WordPress
<div class="image-nav">
  <?php next_image_link( false, 'Next image &raquo;' ); ?>
</div>

How It Works

  1. When you give link text, the image size is not used.
  2. The text becomes the clickable link.
  3. The link goes to the next attachment page.

Example 2 — Show a thumbnail link

Leave the text out to show the next image as a thumbnail.

WordPress
<?php next_image_link( 'thumbnail' ); ?>

How It Works

  1. With no text, WordPress shows the image in the size you pass.
  2. The thumbnail is wrapped in a link to the next attachment page.
  3. Use a bigger size like medium for a larger preview.

Example 3 — Show both previous and next

Put both links in an image navigation block.

WordPress
<nav class="image-nav">
  <?php previous_image_link( false, '&laquo; Previous' ); ?>
  <?php next_image_link( false, 'Next &raquo;' ); ?>
</nav>

How It Works

  1. previous_image_link() goes to the earlier image.
  2. next_image_link() goes to the later image.
  3. Each one prints nothing if there is no image in that direction.

Frequently Asked Questions

It prints a link to the next image attached to the same post, from an image attachment page.
In an attachment template such as image.php or attachment.php.
Yes. Pass false for the size and your text as the second argument.
Nothing is printed.
previous_image_link() prints the link to the previous image.

Browse all post functions

Open the functions index for simple guides with examples and FAQs.

Post Functions Index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful