aioseo_sitemap_images

Purpose & version added

This filter can be used to add or remove sitemap images for a specific post.

Arguments (1)

  1. $images (array) – A list of images.
  2. $post (object) – The current post object.

Example code snippet

The code snippet below is just an example of how this filter can be used. In the example below, we’ll add an image from an Image ACF field with the custom_image key.

add_filter( 'aioseo_sitemap_images', 'aioseo_filter_sitemap_images', 10, 2 );
function aioseo_filter_sitemap_images( $images, $post ) {
	if ( ! function_exists( 'get_field' ) ) {
		return $images;
	}

	$customImage = get_field( 'custom_image', $post->ID );
	if ( ! empty( $customImage ) ) {
		$images[] = wp_get_attachment_image_url( $customImage['id'] );
	}

	return $images;
}

Changelog

VersionDescription
4.1.3Introduced.
4.1.7Added the $post parameter.