Created
October 30, 2015 16:40
-
-
Save E-VANCE/227404841abe29398334 to your computer and use it in GitHub Desktop.
JSON sitemap generation for use with UnCSS (+ Sage theme)
This file contains 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
<?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