WordPress in “Couch Mode”?

I am trying to setup a “Couch Mode” (distraction free reading) on my WordPress blog as laid out in this article.

The guide in the article follows these steps:

Read More
  1. Create a new page in WordPress with slug read

  2. Add the following rewrite rule at the top of the .htaccess file:

    RewriteRule ^read/([0-9]+)/?$ /read/?u=$1 [QSA,L]

  3. Save this file as page-read.php

  4. Add this link to to single.php of my theme using <?php the_ID(); ?>

I did everything as per the article but when I click the “Read story without the clutter” link on my posts it throws an error:

Not Found

The requested URL /read/761/ was not found on this server.

My local development wordpress installation is: localhost/techylab/

While the post where I am trying this Couch Mode is: localhost/techylab/761/something

Related posts

Leave a Reply

1 comment

  1. 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' );