Skip to content

Instantly share code, notes, and snippets.

@micalexander
Created May 23, 2013 17:16
Show Gist options
  • Select an option

  • Save micalexander/5637739 to your computer and use it in GitHub Desktop.

Select an option

Save micalexander/5637739 to your computer and use it in GitHub Desktop.
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' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment