/* FSH_VIDEO_SITEMAP_START */
if ( ! function_exists( 'fsh_video_xml_text' ) ) {
function fsh_video_xml_text( $value ) {
return htmlspecialchars( (string) $value, ENT_XML1 | ENT_COMPAT, 'UTF-8' );
}
}
if ( ! function_exists( 'fsh_video_sitemap_text' ) ) {
function fsh_video_sitemap_text( $value, $limit = 1800 ) {
$value = wp_strip_all_tags( strip_shortcodes( (string) $value ) );
$value = preg_replace( '/\s+/', ' ', $value );
$value = trim( $value );
if ( strlen( $value ) > $limit ) {
$value = substr( $value, 0, max( 0, $limit - 3 ) ) . '...';
}
return $value;
}
}
if ( ! function_exists( 'fsh_video_sitemap_description' ) ) {
function fsh_video_sitemap_description( $post ) {
$description = get_the_excerpt( $post );
if ( ! $description ) {
$description = $post->post_content;
}
$description = fsh_video_sitemap_text( $description );
return $description ? $description : get_the_title( $post ) . ' machine video from Fangshiheng.';
}
}
if ( ! function_exists( 'fsh_output_video_sitemap_xml' ) ) {
function fsh_output_video_sitemap_xml() {
$path = isset( $_SERVER['REQUEST_URI'] ) ? parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ) : '';
$path = '/' . ltrim( (string) $path, '/' );
if ( '/video-sitemap.xml' !== rtrim( $path, '/' ) ) {
return;
}
$projects = get_posts(
array(
'post_type' => 'project',
'post_status' => 'publish',
'posts_per_page' => 200,
'meta_key' => '_fsh_product_video_url',
'orderby' => 'modified',
'order' => 'DESC',
)
);
status_header( 200 );
nocache_headers();
header( 'Content-Type: application/xml; charset=utf-8' );
echo '<' . '?xml version="1.0" encoding="UTF-8"?' . '>' . "\n";
echo '' . "\n";
foreach ( $projects as $project ) {
$post_id = $project->ID;
$video_url = get_post_meta( $post_id, '_fsh_product_video_url', true );
$thumb_url = get_the_post_thumbnail_url( $post_id, 'large' );
if ( ! $video_url || ! $thumb_url ) {
continue;
}
$is_video_file = preg_match( '/\.(mp4|m4v|webm)(\?.*)?$/i', $video_url );
echo " \n";
echo ' ' . fsh_video_xml_text( get_permalink( $post_id ) ) . "\n";
echo ' ' . fsh_video_xml_text( get_post_modified_time( DATE_W3C, true, $post_id ) ) . "\n";
echo " \n";
echo ' ' . fsh_video_xml_text( $thumb_url ) . "\n";
echo ' ' . fsh_video_xml_text( get_the_title( $post_id ) . ' Machine Video' ) . "\n";
echo ' ' . fsh_video_xml_text( fsh_video_sitemap_description( $project ) ) . "\n";
if ( $is_video_file ) {
echo ' ' . fsh_video_xml_text( $video_url ) . "\n";
} else {
echo ' ' . fsh_video_xml_text( $video_url ) . "\n";
}
echo ' ' . fsh_video_xml_text( get_the_date( DATE_W3C, $post_id ) ) . "\n";
echo " yes\n";
echo " \n";
echo " \n";
}
echo "\n";
exit;
}
}
add_action( 'template_redirect', 'fsh_output_video_sitemap_xml', 0 );
if ( ! function_exists( 'fsh_add_video_sitemap_to_robots' ) ) {
function fsh_add_video_sitemap_to_robots( $output, $public ) {
$line = 'Sitemap: ' . home_url( '/video-sitemap.xml' );
if ( false === strpos( $output, $line ) ) {
$output = rtrim( $output ) . "\n" . $line . "\n";
}
return $output;
}
}
add_filter( 'robots_txt', 'fsh_add_video_sitemap_to_robots', 20, 2 );
/* FSH_VIDEO_SITEMAP_END */
https://fangshiheng.com/post-sitemap.xml
2026-05-22T05:46:32+00:00
https://fangshiheng.com/page-sitemap.xml
2026-06-13T04:03:28+00:00
https://fangshiheng.com/project-sitemap.xml
2026-06-22T05:56:49+00:00
https://fangshiheng.com/case_study-sitemap.xml
2026-06-15T02:16:57+00:00
https://fangshiheng.com/category-sitemap.xml
2026-05-22T05:46:32+00:00
https://fangshiheng.com/project-category-sitemap.xml
2026-06-22T08:17:06+00:00