Accessing a comprehensive list of the pages you have in your WordPress CMS is quite simple, especially with the WordPress SEO plugin. The WordPress function ‘wp_list_pages’ is an excellent method of quickly retrieving or displaying such information. It provides a full site-map so you can see how many pages you have and the titles of each page. Unfortunately though, as helpful as this is, there is no function in Yoast to exclude pages that are set to ‘no index’.
What Are No Index Pages?
The reason for labelling a page as ‘no index’ is to prevent Google from crawling it. By including a no index meta tag in a page code, you can stop it from appearing in Google Search. So when Googlebot next visits the page it will recognise the no index tag and drop it entirely from its search results; regardless of whether other sites link to it or not. Consequently, pages that aren’t indexed will not contribute towards your overall site’s SEO performance.
Why Hide My Non-Indexed Pages?
There are many reasons for wanting to hide your no index pages. As mentioned above, pages that aren’t indexed will have no effect on your site’s SEO performance. So if you want to see how your site is performing and what can be improved, looking at your non-indexed pages will be a waste of time and energy. If you own a particularly large site with lots of pages, you only want to see the pages that matter. Everything else is space filler and can often cloud one’s judgement of their site performance.
Lime Web Development Solution
To get around this issue and hide you no index pages from your wp_list_pages, simply pop this code snippet into your functions file:
add_filter( 'get_pages', 'lwd_exclude_no_indexes_from_wp_list_pages', 10, 2 ); function lwd_exclude_no_indexes_from_wp_list_pages( $pages, $args ) { if( array_key_exists( 'walker', $args ) ) { foreach ( $pages as $key => $item ) { $_yoast_wpseo_meta_robots_noindex = get_post_meta( $item->ID, '_yoast_wpseo_meta-robots-noindex', true ); if( $_yoast_wpseo_meta_robots_noindex == 1 ) unset( $pages[$key] ); } } return $pages; } function lwd_no_plug_html_sitemap() { $pages = wp_list_pages([ 'echo' => false, 'title_li' => '' ]); return $pages; } add_shortcode( 'lwd_no_plug_html_sitemap', 'lwd_no_plug_html_sitemap' );
Then edit the pages you don’t want to appear in the sitemap. You may already have these set if you are already using the Yoast SEO plugin.
Finally, create a new page and call it “SiteMap”, the only thing you want in here is our new shortcode – [ lwd_no_plug_html_sitemap ] – and job done!