How to Fix Post Previews in WordPress

Update: This post applies to older versions of WordPress. For more recent versions of WordPress, see solutions in the comments below.

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.

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.

6 thoughts on “How to Fix Post Previews in WordPress

  1. peter

    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.

  2. Kristina

    This post is way old and now we’re halfway through v3, but since this post comes up on the first page when googling ‘post previews don’t work’ I figured I’d post a link to the solution for anyone who happens across this post.

    I recently solved the problem of post previews going to the site index page or resulting in a 404 error. The cause of this is when your “Site URL” and “Blog URL” are different. Many people do this for security reasons (and if you don’t, you probably should) but due to a minor bug this causes a whole lot of problems.

    Here’s the solution:

    It details how to fix the problem AND how to fix the other problem I ran into when you still need to keep your old site index page.

    The bug is being tracked here: If you follow the instructions on how to give wordpress it’s own directory and it still doesn’t work, make sure to refresh your permalinks. To do this, simply go to Settings > Permalinks and hit save. No need to change anything from one structure and then back again.

    Hitting save will save your current settings (again) but it will force wordpress to recycle the settings and will make the changes you just did active.

Leave a Reply