micalexander
5/23/2013 - 5:16 PM

wordpress:snippet:endpoint print

wordpress:snippet:endpoint print

<?php
// Register "Print" Custom Endpoint, e.g. /listing/mylisting/print/ via http://make.wordpress.org/plugins/2012/06/07/rewrite-endpoints-api/
function az_add_print_endpoint() {
    add_rewrite_endpoint( 'print', EP_PERMALINK );
}
add_action( 'init', 'az_add_print_endpoint' );

function az_print_endpoint_redirect() {
	global $wp_query;

	// if this is not a request for print or a singular object then bail
	if ( ! isset( $wp_query->query_vars['print'] ) || ! is_singular() )
		return;

	// include custom template
	include(locate_template('template-print-listing.php'));
	exit;
}
add_action( 'template_redirect', 'az_print_endpoint_redirect' );