add function problem
-
Hi,
I have this code on my functions.php that was preventing from adding new menu items. I would like to know what is wrong with it.
It does generate the site map and all but as I said it prevents new menu items from being added.
/* sitemap */ add_action( "save_post", "sitemap" ); function sitemap() { $posts = get_posts( array( 'numberposts' => -1, 'orderby' => 'modified', 'post_type' => array( 'post', 'page' ), 'order' => 'DESC' )); header('Content-Type: text/xml; charset=' . get_bloginfo('charset'), true); header('X-Robots-Tag: noindex, follow', true); $sitemap .= '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?> <?xml-stylesheet type="text/xsl" href="' . get_stylesheet_directory_uri() . '/sitemap.xsl' . '"?> <!-- generated-on="' . date('Y-m-d\TH:i:s+00:00') . '" --> <!-- generator-version="1.0" --> <urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://www.sitemaps.org/schemas/sitemap/0.9 https://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> '; $sitemap .= '<url> <loc>' . esc_url( home_url( "/" ) ) . '</loc> <changefreq>Daily</changefreq> <priority>1.0</priority> </url>'; foreach( $posts as $post ) { setup_postdata( $post); $postdate = explode( " ", $post->post_modified ); $sitemap .= '<url> <loc>' . get_permalink( $post->ID ) . '</loc> <lastmod>' . $postdate[0] . 'T' . $postdate[1] . '+00:00' . '</lastmod> <changefreq>Weekly</changefreq> <priority>0.5</priority> </url>'; } $sitemap .= '</urlset>'; $fop = fopen( ABSPATH . "sitemap.xml", 'w' ); fwrite( $fop, $sitemap ); fclose( $fop ); } /*end of sitemap */
Thanks
The page I need help with: [log in to see the link]
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘add function problem’ is closed to new replies.