Home / Admin / Add Image to Sitemap From an Image ACF Field
Duplicate Snippet

Embed Snippet on Your Site

Add Image to Sitemap From an Image ACF Field

This filter can be used to add an image from an Image ACF field with the "custom_image" key.

80+
Code Preview
php
<?php
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;
}

Comments

Add a Comment