How to Fix Post Previews in WordPress

I’ve used WordPress for a couple of months now, and so far I really like it. It’s free, it’s pretty easy to set up, it’s extensible, and the WordPress user community has created a huge number of really great WordPress themes and plug-ins. In all, WordPress does a really good job of helping you publish and syndicate content.

WordPress Complete: set up, customize, and market your blog

However, WordPress does have bugs. There is one bug in particular in WordPress 2.0x that makes it essentially useless–one that can occur if you change your permalink structure from the default. When this happens, your preview pane will always show you an error indicating that the post wasn’t found, instead of showing you a preview of the post you’re writing. The rest of this post describes a bug fix that seems to work well for this problem.

First, make sure you’ve entered a post slug. If you’ve changed your permalink structure to include the post slug, the preview won’t work if you don’t enter a post slug. It’s easy to forget to enter a post slug before you first try to preview a new post. If you’ve filled in the post slug and you’re still seeing a “404 Not Found” message in your preview pane, then read on.

To fix this bug, you need to modify one of the core WordPress files. Caveat emptor, of course; you should only make the following change if you agree to accept responsibility for any damage to your web site that results from making the change. However, I have tested this fix with WordPress 2.0.5, 2.0.7, and 2.0.9 and I have had no problems as a result. On the other hand, I have not yet tested the fix with WordPress 2.1 (because my ISP doesn’t yet support the requisite version of MySQL). Now that the dire warnings are out of the way, if you wish to proceed you should edit the file wp‑includes/template‑functions‑links.php, search for the following text (on line 52 in my version of the file):

if ( '' != $permalink && 'draft' != $post->post_status ) {

and change it so that it reads:

if ( '' != $permalink ) {

Hopefully a future version of WordPress will include this fix, but until then this should save you a lot of trouble if you use a non-standard permalink structure.

Share this Post

del.icio.us Digg Reddit Technorati Help

5 Responses to “How to Fix Post Previews in WordPress”

  1. scott Says:

    Hm. Changing that line of code has no effect on my 2.0.1 installation.

  2. pjl Says:

    Sorry, I haven’t tested with that version of WordPress. However, you might want to upgrade to the latest 2.0.x release anyhow because there have been several security patch releases since WordPress 2.0.1 shipped. The current 2.0 patch is 2.0.10, which is available here: http://wordpress.org/download/release-archive/

  3. peter Says:

    Template‑functions‑links.php doesn’t seem to be included with version 2.1.3 — however, the line of code you mention happens to be at line 52 of link-template.php, so maybe it was renamed. At any rate, changing that line didn’t solve my preview problem, which was the “Sorry, no posts matched your criteria” preview bug rather than the 404 bug. Oh well.

  4. Efox Says:

    Changing that in link-template.php solved my problem, many thanks!

  5. Tari Says:

    Unfortunately it doesn’t fix my problem. Looks like the development fixed this bug, because it was already included. Thanks anyway.

Leave a Reply