Using WordPress ‘get_next_image_link()’ PHP function

The get_next_image_link() WordPress PHP function retrieves the next image link that shares the same post parent.

Usage

get_next_image_link( $size, $text )

Example:

Input:
echo get_next_image_link('medium', 'Next Image');

Output:
A medium-sized image link with the text “Next 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 is ‘thumbnail’.
  • $text (string|false) Optional: Link text. Default is false.

More information

See WordPress Developer Resources: get_next_image_link()

Examples

Explanation: This code will display the link to the next image with the default ‘thumbnail’ size.

echo get_next_image_link();

Explanation: This code will display the link to the next image with a custom size of 200×200 pixels.

echo get_next_image_link(array(200, 200));

Explanation: This code will display the link to the next image with the registered ‘medium’ size.

echo get_next_image_link('medium');

Explanation: This code will display the link to the next image with the custom text “Click for Next Image”.

echo get_next_image_link('thumbnail', 'Click for Next Image');

Explanation: This code will display the link to the next image with a custom size of 300×300 pixels and the custom text “View Next Image”.

echo get_next_image_link(array(300, 300), 'View Next Image');