Home WordPress Posts Functions next_image_link() WordPress next_image_link() Function 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().
<?php
next_image_link( 'thumbnail', 'Next image' ); Call What 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 »' )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 next_image_link( string|int[] $size = 'thumbnail', string|false $text = false ): void Parameters Parameter Description $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 Value Description void Nothing is returned. The link is printed.
WordPress Examples Three short examples. Each one shows the code and what it prints.
1. Show a text link 2. Show a thumbnail link 3. Show both previous and next Example 1 — Show a text link Print a simple Next image link.
<div class="image-nav">
<?php next_image_link( false, 'Next image »' ); ?>
</div> <div class="image-nav">
<a href='https://example.com/my-gallery/beach/'>Next image »</a>
</div> How It Works When you give link text, the image size is not used. The text becomes the clickable link. 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.
<?php next_image_link( 'thumbnail' ); ?> <a href='https://example.com/my-gallery/beach/'><img width="150" height="150" src="https://example.com/wp-content/uploads/2026/11/beach-150x150.jpg" class="attachment-thumbnail size-thumbnail" alt="" /></a> How It Works With no text, WordPress shows the image in the size you pass. The thumbnail is wrapped in a link to the next attachment page. 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.
<nav class="image-nav">
<?php previous_image_link( false, '« Previous' ); ?>
<?php next_image_link( false, 'Next »' ); ?>
</nav> <nav class="image-nav">
<a href='https://example.com/my-gallery/sunset/'>« Previous</a>
<a href='https://example.com/my-gallery/forest/'>Next »</a>
</nav> How It Works previous_image_link() goes to the earlier image.next_image_link() goes to the later image.Each one prints nothing if there is no image in that direction. Frequently Asked Questions What does next_image_link() do? It prints a link to the next image attached to the same post, from an image attachment page.
Where do I use it? In an attachment template such as image.php or attachment.php.
Can I use text instead of a thumbnail? Yes. Pass false for the size and your text as the second argument.
What if there is no next image? Nothing is printed.
What is the opposite function? 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 Developer, cloud engineer, and technical writer
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
Helpful Share Copy link Suggestion