Notice: There is no legacy documentation available for this item, so you are seeing the current documentation.
Purpose & version added
This filter can be used to add or remove sitemap images for a specific post.
Arguments (1)
- $images (array) – A list of images.
- $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
Version | Description |
4.1.3 | Introduced. |
4.1.7 | Added the $post parameter. |