• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2665

Original Genesis Tutorials & 5000+ Guaranteed Code

Snippets

  • Support
  • Newsletter
  • Videos
  • Log in

Premium Member? - Request custom code

Add Custom Post Type Entries To Genesis Site Map

This code uses wp_get_archives with the post_type=portfolio parameter to add custom post type pages to the site map included in Genesis.

Here’s the code you can add to your child themes functions file.

add_filter( 'genesis_sitemap_output', 'modify_sitemap' );
function modify_sitemap() {
 
    $heading = ( genesis_a11y( 'headings' ) ? 'h2' : 'h4' );
 
    $sitemap  =  sprintf( '<%2$s>%1$s</%2$s>', __( 'Pages:', 'genesis' ), $heading );
    $sitemap .=  sprintf( '<ul>%s</ul>', wp_list_pages( 'title_li=&echo=0' ) );
 
    $sitemap .=  sprintf( '<%2$s>%1$s</%2$s>', __( 'Categories:', 'genesis' ) , $heading );
    $sitemap .=  sprintf( '<ul>%s</ul>', wp_list_categories( 'sort_column=name&title_li=&echo=0' ) );

    $sitemap .=  sprintf( '<%2$s>%1$s</%2$s>', __( 'Authors:', 'genesis' ) , $heading );
    $sitemap .=  sprintf( '<ul>%s</ul>', wp_list_authors( 'exclude_admin=0&optioncount=1&echo=0' ) );

    $sitemap .=  sprintf( '<%2$s>%1$s</%2$s>', __( 'Monthly:', 'genesis' ) , $heading );
    $sitemap .=  sprintf( '<ul>%s</ul>', wp_get_archives( 'type=monthly&echo=0' ) );
 
    $sitemap .=  sprintf( '<%2$s>%1$s</%2$s>', __( 'Recent Posts:', 'genesis' ) , $heading );
    $sitemap .=  sprintf( '<ul>%s</ul>', wp_get_archives( 'type=postbypost&limit=100&echo=0' ) );
    
    $sitemap .=  sprintf( '<%2$s>%1$s</%2$s>', __( 'CPT Portfolio Items:', 'genesis' ) , $heading );
    $sitemap .=  sprintf( '<ul>%s</ul>', wp_get_archives( 'type=postbypost&limit=10&echo=0&post_type=portfolio' ) );
      
    return $sitemap;
}

Swap out portfolio in the above code with the name of your CPT.

You could also use wp_list_pages like this:

$sitemap .=  sprintf( '<%2$s>%1$s</%2$s>', __( 'Portfolio Items:', 'genesis' ) , $heading );
$sitemap .=  sprintf( '<ul>%s</ul>', wp_list_pages( 'title_li=&echo=0&post_type=portfolio' ) );

Related Code Snippets

  • Modify The Genesis Sitemap
  • Remove Page From Genesis Sitemap Archive

Custom Post Type

Reader Interactions

Comments

  1. Micki says

    December 15, 2017 at 1:53 pm

    Hi! Thank you for this! What if I just wanted the CPT titles to list/link on the sitemap, versus a list of posts below the CPT title? Any ideas on how I can do this? I have way too many posts/categories under the CPT’s to have them listed, but would be great to have an easy link for folks to go to that CPT. I hope this makes sense :).

    Log in to Reply
    • Brad Dalton says

      December 16, 2017 at 5:28 am

      Micki, You can do that by modifying the PHP code which is something i support for members.

      Log in to Reply

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

PHP Code

template_include

get_body_class

if else

array

class_exists

foreach

sprintf

add_action

printf

variable

Advertise · WPEngine · Genesis · Log in

  • How Premium Membership Works
  • Sign Up
  • Support
  • Subscription Details/Invoice
  • Tagged Tutorials
  • Access-Download Problems