Plain Text Pages/Posts in WordPress

While experimenting with WordPress i was tasked with a situation where i am suppose to present some static text content on the website. However uploading a text file was out of question and the author wanted to keep everything controlled inside WordPress.

So i created a simple text only theme template for him and this combined with the plugin allowing custom permalinks provide us with options of having a custom name and still showing the WordPress page as static text only page.

Template Page is available online at : https://github.com/anantshri/wordpress_tricks/blob/master/plain_text_page.php

Source Code for viewing pleasure.

<?php
/*
* This templete will show all content as text only. in order to retain text only post while you save text in wordpress editor i would suggest add the text inside <pre></pre> tag
* the below code will remove any html / php tag that it will find in content and will only display the textual part of the file.
*/
header('Content-type: text/plain'); 
/**
 * Template Name: content text only
 * Description: Only Post content text only
 * @package WordPress 
 */
if (have_posts()) : 
	while (have_posts()) : the_post(); 
		$content=get_the_content();
		$cnt=strip_tags($content);
		echo $cnt;
	endwhile; // end of the loop. 
endif; 
?>

P.S. I suspect there might be better ways of dealing with this situation but my limited google skills didn’t provided a result in first 5 minutes so instead i spend 2 minutes on crafting this. If you do know a better way then feel free to suggest it via comments.

Do you like what you read, What to share it

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.