WordPress All Page Listings ShortCode

For when you need a list of all the pages on a WordPress website. Add this to functions.php and use the shortcode [page_listing] to a new Page. This will also create a CSV file in the theme’s directory so you can easily import it into a spreadsheet program like Google Sheets.

<?php 
function page_listing(){
    $pages = get_pages();
    $html = '<ul>';
    $csv_arr = array();
    $csv_arr[] = array("Title", "Permalink", "In Progress", "New/Revised Content Added", "Links Added and Tested", "SEO", "Hero Photo Placed/Cropped Appropriately", "Styling", "Needs Added to Navigation", "Reviewed by NAME (desktop/mobile)", "Reviewed by NAME/NAME", "Assigned to", "Notes", "Page needs to be deleted", "Final Notes Before Launch", "Reviewed by Dev Team");
    foreach($pages as $page){
        $html .= '<li>';
        $html .= $page->post_title .',   <a href="'.get_permalink($page->ID).'">'.get_permalink($page->ID).'</a>';
        $html .= '</li>';
        $csv_arr[] = array($page->post_title, get_permalink($page->ID));
    }
    $html .= '</ul>';
	$fp = fopen(get_template_directory().'/page_listings.csv', 'w');
    foreach($csv_arr as $row){
	    fputcsv($fp, $row);
    }
    fclose($fp);
    return $html;
}
add_shortcode("page_listing", 'page_listing');

GitHub Link