Rewrite Endpoint to load post with different templates

<?php
/**
* Rewrite Endpoint
*
*/
function be_endpoint() {
add_rewrite_endpoint( 'section', EP_PERMALINK );
}
add_action( 'init', 'be_endpoint' );
/**
* Custom Templates
*
*/
function be_custom_templates( $template ) {
if( ! is_singular( array( 'company', 'program', 'product' ) ) )
return $template;
$post_type = get_post_type();
$section = get_query_var( 'section' ) ? get_query_var( 'section' ) : 'overview';
$template = get_query_template( $post_type . '-' . $section );
return $template;
}
add_action( 'template_include', 'be_custom_templates' );
view raw functions.php hosted with ❤ by GitHub

Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk