get_adjacent_image_link( bool $prev = true, string|int[] $size = 'thumbnail', bool $text = false ): string

In this article

Gets the next or previous image link that has the same post parent.

Description

Retrieves the current attachment object from the $post global.

Parameters

$prevbooloptional
Whether to display the next (false) or previous (true) link.

Default:true

$sizestring|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'.

Default:'thumbnail'

$textbooloptional
Link text.

Default:false

Return

string Markup for image link.

Source

// These ones should just be omitted altogether if they are blank.
foreach ( array( 'poster', 'loop', 'autoplay', 'preload', 'muted' ) as $a ) {
	if ( empty( $html_atts[ $a ] ) ) {
		unset( $html_atts[ $a ] );
	}
}

$attr_strings = array();
foreach ( $html_atts as $attribute_name => $attribute_value ) {
	if ( in_array( $attribute_name, array( 'loop', 'autoplay', 'muted' ), true ) && true === $attribute_value ) {
		// Add boolean attributes without their value for true.
		$attr_strings[] = esc_attr( $attribute_name );
	} elseif ( 'preload' === $attribute_name && ! empty( $attribute_value ) ) {
		// Handle the preload attribute with specific allowed values.
		$allowed_preload_values = array( 'none', 'metadata', 'auto' );
		if ( in_array( $attribute_value, $allowed_preload_values, true ) ) {
			$attr_strings[] = sprintf( '%s="%s"', esc_attr( $attribute_name ), esc_attr( $attribute_value ) );
		}
	} elseif ( ! empty( $attribute_value ) ) {
		// For non-boolean attributes, add them with their value.
		$attr_strings[] = sprintf( '%s="%s"', esc_attr( $attribute_name ), esc_attr( $attribute_value ) );
	}
}

$html = '';

if ( 'mediaelement' === $library && 1 === $instance ) {
	$html .= "<!--[if lt IE 9]><script>document.createElement('video');</script><![endif]-->\n";
}

$html .= sprintf( '<video %s controls="controls">', implode( ' ', $attr_strings ) );

$fileurl = '';
$source  = '<source type="%s" src="%s" />';

foreach ( $default_types as $fallback ) {
	if ( ! empty( $atts[ $fallback ] ) ) {
		if ( empty( $fileurl ) ) {
			$fileurl = $atts[ $fallback ];
		}
		if ( 'src' === $fallback && $is_youtube ) {
			$type = array( 'type' => 'video/youtube' );
		} elseif ( 'src' === $fallback && $is_vimeo ) {
			$type = array( 'type' => 'video/vimeo' );
		} else {
			$type = wp_check_filetype( $atts[ $fallback ], wp_get_mime_types() );
		}
		$url   = add_query_arg( '_', $instance, $atts[ $fallback ] );
		$html .= sprintf( $source, $type['type'], esc_url( $url ) );
	}
}

if ( ! empty( $content ) ) {
	if ( str_contains( $content, "\n" ) ) {
		$content = str_replace( array( "\r\n", "\n", "\t" ), '', $content );
	}
	$html .= trim( $content );

Changelog

VersionDescription
5.8.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.