/hreflang support on top of the image support here, via the // `acez_seo_sitemap_renderer_class` filter. class ImageAwareSitemapRenderer extends \WP_Sitemaps_Renderer { // protected, not private — AcezSeoPro\Sitemap\VideoAwareSitemapRenderer // extends this class and reuses the same namespace URI (M56, Pro video sitemap). protected const IMAGE_NS = 'http://www.google.com/schemas/sitemap-image/1.1'; /** * User-defined URL exclusions (Sitemap tab) are applied HERE, in the one * public method core calls for every sitemap page — NOT in * get_sitemap_xml(), because Pro's ProSitemapRenderer fully overrides * that method (video/hreflang) and would silently bypass the rules; * render_sitemap() is inherited by the whole renderer chain. * * @param array> $url_list */ public function render_sitemap( $url_list ) // phpcs:ignore WordPress.NamingConventions.ValidVariableName -- inherited parameter name. { parent::render_sitemap( ( new UrlExclusions() )->filter( (array) $url_list ) ); } /** * @param array> $url_list * * @return string|false */ public function get_sitemap_xml( $url_list ) { $urlset = new \SimpleXMLElement( sprintf( '%1$s%2$s%3$s', '', $this->stylesheet, '' ) ); foreach ( $url_list as $url_item ) { $url = $urlset->addChild( 'url' ); $images = array(); foreach ( $url_item as $name => $value ) { if ( 'loc' === $name ) { $url->addChild( $name, esc_url( $value ) ); } elseif ( in_array( $name, array( 'lastmod', 'changefreq', 'priority' ), true ) ) { $url->addChild( $name, esc_xml( (string) $value ) ); } elseif ( 'images' === $name && is_array( $value ) ) { $images = $value; } // Anything else (a stray custom key from a third-party // filter) is silently ignored here too — same as core. } foreach ( $images as $image_url ) { $image_node = $url->addChild( 'image:image', '', self::IMAGE_NS ); $image_node->addChild( 'image:loc', esc_url( (string) $image_url ), self::IMAGE_NS ); } } return $urlset->asXML(); } }