Published Page List in WordPress

,

If you are ever looking for a quick and easy way to list all of the pages on your site that are published here is how I accomplished it.  It uses the WordPress get_pages() function to then output the title and permalink if the post status is published.

//use [get_all_pages] to display list of pages on a page
add_shortcode('get_all_pages','get_all_pages');
function get_all_pages() {
    /* if you wanted to limit it being output by IP address then put your IP address in the below line where the xxxx's are and also uncomment out the close bracket. */
    //if ( $_SERVER['REMOTE_ADDR'] == 'xxxx' ) {
        $outputHtml = '';
        $sites_pages = get_pages();
        foreach ($sites_pages as $page_data) {
            $page_permalink = get_permalink($page_data->ID);
            if ($page_data->post_status == 'publish') $outputHtml .= $page_data->post_title . " - " . $page_permalink . "<br>";
        }
        return $outputHtml;
    //}
}

 

Skills

Posted on

January 18, 2019

Submit a Comment

Your email address will not be published.