Skip to content

Plain Text Custom Post Type

Screen shot of the plain text post list page.

Just uploaded a plugin to the WordPress SVN that creates a plain text custom post type. It’s a post that has absolutely no formatting, and even strips out the WordPress theme leaving just the text.

What’s the point?

I’m playing around with a network installation of WordPress. One of the sites that I’m moving to the network was originally a Dreamweaver site and needs a JavaScript file that’s specific to that site. But one of the advantages of moving this site to a WP network is that I don’t have to do as much individually to an specific site so I didn’t want to have to customize a theme for a single site. With this plugin I’m able to create a post that contains the contents of the external JavaScript file, I don’t have to touch the theme files or, and any customization of that file doesn’t affect any of the other sites on the network.

How’s it work?

Plain Text Files added under the Pages tab

After activating the plugin a new menu item is added under the Pages tab. Adding a new Plain Text File post works just like any other post except there are fewer meta boxes on the page and Tiny MCE is disabled.

The other thing you might notice is that the tab key doesn’t work like it’s supposed to when typing in the text area. Instead of moving on to the next field like is normal for a web page, the tab key works like it does in a normal text editor.

Two new fields are added to the post meta box just above the Publish button.

The first allows you to pick what type of file you’re editing; CSS, JavaScript, or plain text. This affects the Content-type header that is sent with your file. A CSS files gets text/css, JavaScript gets text/javascript, and plain text gets text/plain. For most browsers this won’t matter, but it’s done anyway.

Publish meta box for the plain text custom post type

Where it does matter is if you check the box to auto load your file. This will add a link to your plain text post into the head section of your theme. So if you create a JavaScript file and select automatic linking, WordPress will put a link to the post including the <script> tags. Same with CSS.

A plain text file will not link even if you check the box. Linking to a non-CSS, non-JavaScript file doesn’t make sense in the header.

Need a demo?

Not much to see since it’s just linking to an external JavaScript file, but the site I wrote this for is QuickCalcs.info.

Download

You can download Plain Text Custom Post Type from the WordPress plugin library or through WordPress.

Published inWordPress

Be First to Comment

Leave a Reply

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