Created
August 20, 2024 21:01
-
-
Save BrookeDot/151aee9fcb7eed370b007b8575246116 to your computer and use it in GitHub Desktop.
MSM Sitemap customization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function vip_customize_msm_sitemap_entry( $url ) { | |
if ( $url instanceof SimpleXMLElement ) { | |
// Add images to the sitemap entry. | |
$post_id = get_the_ID(); | |
$thumbnail_id = get_post_thumbnail_id( $post_id ); | |
if ( $thumbnail_id ) { | |
// Get the URL of the featured image. | |
$image_url = wp_get_attachment_url( $thumbnail_id ); | |
if ( $image_url ) { | |
// Add the <image:image> tag with the featured image. | |
$image_tag = $url->addChild( 'image:image' ); | |
$image_tag->addChild( 'image:loc', esc_url( $image_url ) ); | |
// Optionally add the image title. | |
$image_title = get_the_title( $thumbnail_id ); | |
if ( $image_title ) { | |
$image_tag->addChild( 'image:title', esc_html( $image_title ) ); | |
} | |
} | |
} | |
// Remove the changefreq element. | |
if ( isset( $url->changefreq ) ) { | |
unset( $url->changefreq[0] ); | |
} | |
// Remove the priority element. | |
if ( isset( $url->priority ) ) { | |
unset( $url->priority[0] ); | |
} | |
} | |
return $url; | |
} | |
add_filter( 'msm_sitemap_entry', 'vip_customize_msm_sitemap_entry', 10, 1 ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment