Even if this is not a good practice, printing webpages is common for many internet users. If you’re interested in adding a “Print this” button to your posts, just read this recipe, which also include some info about creating a nice print stylesheet.
Even if this is not a good practice, printing webpages is common for many internet users. If you’re interested in adding a “Print this” button to your posts, just read this recipe, which also include some info about creating a nice print stylesheet.
If you don't know how to create a great print stylesheet, you should definitely read this tutorial.
To include your print stylesheet, add the following line to your header.php file, within the <head> and </head> tags.
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_url'); ?>/print.css" media="print" />
Now we have to create our "Print this" button. Open your single.php file and add the following line:
<a href="javascript:window.print()">Print this Article</a>
Good job! Your visitors are now able to print your posts easily with a nice print styling.
10 Responses
I prefer use wp-print plugin by lesterchan because with this recipe you don’t have a preview of your page…
@Rainbow: You’re right, wp-print is a very nice plugin! Btw, I still think this recipe is interresting if you don’t want to install one more plugin
Good recipe, but it should be pointed out that it’s the print stylesheet that controls the formatting and style of the printed post/article, not the javascript and the “print this page” button.
The “print this page” button is a nice touch, but modern browsers all have a “print” button or menu function that accomplishes the same task.
Also, the “print this page” button you’ve described will not function if the visitor has disabled javascript in their browser, which is something that also has to be taken into consideration.
@RayInPR: Sure all modern browsers have a print button, but many blogs/websites purposes a print button directly in the page, so I thought WordPress users would love to know how to do it
I have heard that 10% of Internet users don’t have Javascript. But seriously, in 2008, who can browse the web without JS? All modern sites uses it…
I had a reader who had problem printing my articles lately and was looking for an alternative to WP-print. Would have solve the problem should I know the existence of this article. Great help anyway.
I also use the Wp-print plugin, but this tutorial is useful also. Thank you very much.
Nicholas
Been meaning to do this for ages! TY!
Will compare with the WP plugin. I’m new to all of this, so will need to see which I can do.
Isn´t the problem with WP-print that it generates duplicate pages and therefore you get SEO problems with duplicate content… ?
At least I have understood it that way and therefore has chosen not to use it.
Trackbacks: