Here’s a method to achieve what you want internally without adding anything to the .htaccess file.
It works by adding a rewrite endpoint named read
, so any single post permalink with read
appended to the end will have a different single post template applied.
For example, if your normal single post permalink is:
localhost/techylab/some-post-title/
The alternate version will be available at:
localhost/techylab/some-post-title/read/
First, add the rewrite endpoint. This goes in your theme’s functions.php
:
function wpa_read_endpoint(){
add_rewrite_endpoint( 'read', EP_PERMALINK );
}
add_action( 'init', 'wpa_read_endpoint' );
After adding this, visit your permalinks settings page in admin to flush the rewrite rules so this endpoint will be added to the rules.
Next, filter the single post template and check for the presence of the read
query var. If it exists, load the template within the theme folder named read.php
. This is your simplified post template with whatever markup and template tags you want. The correct post has already been queried, so no need for a special query to load the post via the ID as in the version you posted, the normal loop will work just like in any other template.
function wpa_read_template( $template="" ) {
global $wp_query;
if( ! array_key_exists( 'read', $wp_query->query_vars ) ) return $template;
$template = locate_template( 'read.php' );
return $template;
}
add_filter( 'single_template', 'wpa_read_template' );