Skip to content

Instantly share code, notes, and snippets.

@E-VANCE
Created October 30, 2015 16:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save E-VANCE/227404841abe29398334 to your computer and use it in GitHub Desktop.
Save E-VANCE/227404841abe29398334 to your computer and use it in GitHub Desktop.
JSON sitemap generation for use with UnCSS (+ Sage theme)
<?php
/**
* Generate JSON sitemap for use with UnCSS
*/
function show_sitemap() {
if (WP_ENV === 'development' && isset($_GET['show_sitemap'])) {
$the_query = new \WP_Query(array('post_type' => 'any', 'posts_per_page' => '-1', 'post_status' => 'publish'));
$urls = array();
while($the_query->have_posts()) {
$the_query->the_post();
$urls[] = get_permalink();
}
// include category-template(s), one would actually suffice...
$categories = get_categories();
foreach($categories as $category) {
$urls[] = home_url().get_category_link( $category->term_id );
}
$urls[] = get_search_link('liebe'); // some search-term to include search-template, should throw at least one result
$urls[] = home_url().'/somethingyouwillneverfind'; // generate 404-template page
$urls[] = home_url(); // include home-url (no static page is used)
die(json_encode($urls));
}
}
add_action('template_redirect', __NAMESPACE__ . '\\show_sitemap');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment