WordPress 2.0: Hide post preview
Published Tuesday, January 3rd, 2006 at 8:44 am
If you're using WordPress 2.0 you may notice one of the cool new features is the post preview. When you save a post or edit a post down at the bottom of the post page you are presented with a preview of your post. This preview shows the whole page (not just the post text), logo, navigation, everything that is on the main page. I really like this feature but I don't always want to use it. Most of the time I don't need to look at it. For example when making a simple change. So it is just a waist of bandwidth and server power. If you read my blog regularly I'm sorry you know that I never just accept these types of things. So I modified the
If you are using WordPress version 2.0.1 then you should replace line 83 in
If you are using WordPress version 2.1 then you should replace line 72 in
Preview is no longer inline so this change is not needed.
/wp-admin/post.php file to allow me to view the preview only when I need it. I considered making this a plugin but as far as I can tell there is no way of preventing the preview page from loading via a plugin. I could easily hide it but the data will still be pulled from the server. So if you would like to make the changes yourself open /wp-admin/post.php and find line 85
<iframe src="<?php the_permalink(); ?>" width="100%" height="600" ></iframe>
and replace it with
<script type="text/javascript">
<!--
function show_preview() {
var elm = document.getElementById("frm_preview");
elm.src = "<?php the_permalink(); ?>";
elm.height = "600";
return false;
}
-->
</script>
<a href="#preview-post" onclick="show_preview();">Show Preview</a>
<iframe id="frm_preview" src="" width="100%" height="10" ></iframe>
I've posted this to the official WordPress tracker for possible inclusion in the next release.
* Edit for 2.0.1*If you are using WordPress version 2.0.1 then you should replace line 83 in
/wp-admin/post.php with:
<script type="text/javascript">
<!--
function show_preview() {
var elm = document.getElementById("frm_preview");
elm.src = "<?php echo add_query_arg('preview', 'true', get_permalink($post->ID)); ?>";
elm.height = "600";
return false;
}
-->
</script>
<a href="#preview-post" onclick="show_preview();">Show Preview</a>
<iframe id="frm_preview" src="" width="100%" height="10" ></iframe>
* Edit for 2.1 *If you are using WordPress version 2.1 then you should replace line 72 in
/wp-admin/post.php with:
<script type="text/javascript">
<!--
function show_preview() {
var elm = document.getElementById("frm_preview");
elm.src = "<?php echo attribute_escape(apply_filters('preview_post_link', add_query_arg('preview', 'true', get_permalink($post->ID)))); ?>";
elm.height = "600";
return false;
}
-->
</script>
<a href="#preview-post" onclick="show_preview();">Show Preview</a>
<iframe id="frm_preview" src="" width="100%" height="10" ></iframe>
* Edit for 2.2 *Preview is no longer inline so this change is not needed.






January 30th, 2006 at 3:48 am
Thanks, I’ve been looking for this for the reasons you cited as well as not wanting my adsense account to be confused by being asked to be shown in the preview pane when they are not even posted on a real url. Good work
January 30th, 2006 at 4:11 pm
Google Adsense and Wordpress 2.0: beware of the preview
Wordpress 2.0 has a preview feature that can cause Adsense problems:
“… because the post hasn’t been published yet, when Google’s bot tries to crawl the page a few seconds later, it will receive a 404 error.”
Google pr…
January 30th, 2006 at 7:54 pm
Tim,
Thanks for the comment. I hadn’t thought of the adsense issue. Also check out Lunacy Unleashed for a way to disable adsence inside the preview page (found via the trackback on Jan. 30).
February 3rd, 2006 at 4:43 pm
Hello
Thank you for this hack!
Regards
Yuri
February 28th, 2006 at 5:57 pm
It may be useful for everyone!
March 14th, 2006 at 1:03 am
Thank you!
March 26th, 2006 at 1:11 am
[...] By far my favorite are the hacks, fixes, and tips. The posts are where something wasn’t working or wasn’t working the way I wanted so I fixed it. I’ve always been doing these type of things but finally I found a medium to efficiently share my experences. I feel quite satisfied being able to share these with others. These also end up being my most popular posts. One example is a fix for a WordPress 2.0 bug that prevented WP from running on windows machines (fixed in WP 2.0.1 version thanks to my bug report). I shared my method for hiding the WordPress post preview. I discovered a fix for a problem debugging Visual Studio applications with .NET 2.0 runtime installed. I also used my blog to spread the word of my first Firefox extension. [...]
June 5th, 2006 at 1:44 am
Nice hack!
This really should be a default option…
July 17th, 2006 at 11:05 am
hey, thanks for the pointer. I had a similar hunch and landed up on this page via google. What I want to know is that if you remove that block from the post.php file, the preview iframe will not be displayed, but will the data still be pulled from the db, and more importantly, since we’re not displaying it, i guess the googlebot will not try to crawl over, because the ad will not even be displayed ?? is that correct, or …
July 18th, 2006 at 4:49 pm
saurab,
If you do not hit the “show preview” link the preview will not be pulled from your sever. The google ad will not be pulled form the server and everyone will be happy.
September 19th, 2006 at 2:29 pm
Arggh thank god someone has fixed this – has been driving me mad! I agree it should be changed to the default option
October 10th, 2006 at 11:27 pm
The 2nd code works perfectly in my WP 2.0.4.
Thnks.
By the way, to hide the adsense in preview mode I’m just inserting the adsense code between an
!is_preview() IF.
November 29th, 2006 at 4:40 am
The code in WP 2.0.5 is different around line #82 in /wp-admin/post.php:
<div id=’preview’ class=’wrap’>
<h2 id=”preview-post”><?php _e(‘Post Preview (updated when post is saved)’); ?> <small class=”quickjump”><a href=”#write-post”><?php _e(‘edit ↑’); ?></a></small></h2>
<iframe src=”<?php echo wp_specialchars(apply_filters(‘preview_post_link’, add_query_arg(‘preview’, ‘true’, get_permalink($post->ID)))); ?>” width=”100%” height=”600″ ></iframe>
</div>
So, the change you made won’t work. Any fixes? Please email it to me at [tbond] at [ideapro.com]. We’re installing the changes on http://www.partnershipinparenting.com/
Thanks for your help!
– Tom Bond,
Webmaster/Designer
IDEAPRO.COM
December 23rd, 2006 at 8:53 am
Hi all!!! Cool site!!!
January 8th, 2007 at 8:42 am
Line 84 in Wordpress 2.0.6 !!
January 8th, 2007 at 8:08 pm
Yes, unfortunately it has to be reinstated every time there is a new version. I usually run a diff on this file before every upload. Combine these lines with the rest of the new file. This feature has been submitted to the WordPress tracker but it is classified as a new feature and therefore will not show up in the root until 2.1.
February 14th, 2007 at 9:30 pm
See the update above for version 2.1. This enhancement has now been delayed to 2.2.
February 21st, 2007 at 10:41 am
Perfect. For some reason, some of my sidebar widgets have been slow loading. When the preview pane was active, this slowed down loading of articles for me to edit. Your change is exactly what I needed to speed up loading the page to write or edit while still keeping preview functionality. Hope this gets in the official release soon.
March 2nd, 2007 at 7:59 am
Thank you so much for posting this code change. The preview was slowing me down, big time. Thanks again!
March 12th, 2007 at 1:00 pm
Thanks a lot! You rules!
October 7th, 2007 at 5:53 pm
perfect!! nowadays… with so many widgets and remote scripts, disabling the preview is a real time saver!! thanks mate!!
January 5th, 2008 at 6:38 am
Thanks very much!!!! This has been driving me insane for several months! Thanks Again :-)
Mike
December 13th, 2008 at 10:23 am
Thanks!,
February 16th, 2009 at 7:55 pm
Let me know if you find something that works. I need something like this for another project.
March 3rd, 2009 at 1:30 pm
Спасибо за статью.. Актуально мне сейчас.. Взяла себе еще перечитать.
February 4th, 2010 at 3:00 pm
hi it seems this website conceals your original referrer what do you think