function create_sitemaps() { $postsForSitemap = get_posts( array( 'posts_per_page' => -1,'orderby' => 'modified','post_type' => array( 'post','page'),'order' => 'DESC')); $sitemap = '' . "\n" . '' . "\n"; $imgmap = '' . "\n" . '' . "\n"; foreach( $postsForSitemap as $post ) { $sitemap .= "\t" . '' . "\n" . "\t\t" . '' .get_permalink( $post->ID ). '' . "\n\t\t" . '' . explode( " ", $post->post_modified )[0] . '' . "\n\t\t" . 'monthly' . // Wie oft ändert sich euer Inhalt? "\n\t" . '' . "\n"; $mediaforpost = get_attached_media( 'image', $post->ID); if (!empty($mediaforpost)) { $imgmap .= "\t" .''."\n"."\t\t".''.get_permalink( $post->ID ).''; foreach( $mediaforpost as $media ) { $imgmap .= "\n\t\t" . ''. "\n\t\t\t"."" . strip_tags($media->guid) . "" . "\n\t\t\t"."" . strip_tags(preg_replace("/&(?!#?[a-z0-9]+;)/", "&", $media->post_title)) . "" . "\n\t\t\t"."". strip_tags(preg_replace("/&(?!#?[a-z0-9]+;)/", "&", $post->post_title)) . "" . "\n\t\t\t"."". 'https://creativecommons.org/licenses/by-nc-sa/4.0/' . "" . // Hier den Link zur Lizenz einfügen "\n\t\t" . '';} $imgmap .= "\n\t" . '' . "\n"; } } $sitemap .= ''; $imgmap .= ''; $fp = fopen( ABSPATH . "/sitemap.xml", 'w' ); fwrite( $fp, $sitemap ); fclose( $fp ); $fp = fopen( ABSPATH . "/imagemap.xml", 'w' ); fwrite( $fp, $imgmap ); fclose( $fp ); } add_action("publish_post", "create_sitemaps"); add_action("publish_page", "create_sitemaps");