-
-
Save johanoloflindberg/49a982b1db9ef358d0de28e44eb79f4b to your computer and use it in GitHub Desktop.
Gist description...
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
add_action( 'init', 'jf_register_my_new_sitemap', 99 ); | |
/** | |
* On init, run the function that will register our new sitemap as well | |
* as the function that will be used to generate the XML. This creates an | |
* action that we can hook into built around the new | |
* sitemap name - 'wp_seo_do_sitemap_my_new_sitemap' | |
*/ | |
function jf_register_my_new_sitemap() { | |
global $wpseo_sitemaps; | |
$wpseo_sitemaps->register_sitemap( 'my_new_sitemap', 'jf_generate_my_new_sitemap' ); | |
} | |
add_action( 'wp_seo_do_sitemap_my_new_sitemap', 'jf_generate_my_new_sitemap' ); | |
/** | |
* Hook into this new action that we've built and output the XML associated with | |
* what information we want to convey. Once the XML is built, set this as our sitemap | |
* data | |
*/ | |
function jf_generate_my_new_sitemap() { | |
global $wpseo_sitemaps; | |
//pull the required data, sort it as needed, build into $my_sitemap_data | |
$my_sitemap_data = '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> | |
<url> | |
<loc>http://mydomain/</loc> | |
<lastmod>2011-04-06T06:40:00+00:00</lastmod> | |
<changefreq>weekly</changefreq> | |
<priority>1</priority> | |
</url> | |
</urlset>'; | |
$wpseo_sitemaps->set_sitemap( $my_sitemap_data ); | |
} | |
add_filter( 'wpseo_sitemap_index', 'jf_add_to_sitemap_index' ); | |
/** | |
* Filter the index page for the sitemaps (sitemap_index.xml) in order to | |
* add our new sitemap. | |
* | |
* @param $current_xml string representing the current index XML being shown | |
* | |
* @return string representing the new index XML to show | |
*/ | |
function jf_add_to_sitemap_index( $current_xml ) { | |
$current_xml .= '<sitemap> | |
<loc>http://mynewdomain/my_new_sitemap-sitemap.xml</loc> | |
<lastmod>2012-10-03T19:42:27+00:00</lastmod> | |
</sitemap>'; | |
return $current_xml; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment