How to: Add a “Print” button to your posts

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

Nov 02 2008 11:04

I prefer use wp-print plugin by lesterchan because with this recipe you don’t have a preview of your page…

Nov 02 2008 11:12

@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 :)

Nov 02 2008 13:26

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.

Nov 02 2008 14:09

@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…

Nov 02 2008 20:46

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.

Nov 05 2008 14:44

I also use the Wp-print plugin, but this tutorial is useful also. Thank you very much.

Nicholas

Nov 09 2008 14:24

Been meaning to do this for ages! TY! :D

Sep 23 2009 14:50

Will compare with the WP plugin. I’m new to all of this, so will need to see which I can do.

Feb 06 2010 22:08

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:

Leave a Comment

* Name, Email, Comment are Required