Thesis Tip #6 – Print Stylesheets

by Bill Erickson on December 2, 2009

Post image for Thesis Tip #6 – Print Stylesheets

(This tutorial is specifically for the Thesis theme, but can be adapted to work with any Wordpress theme).

For a lot of websites, the browser isn’t the only medium through which the site will be viewed. If your visitors will be printing out your posts or pages (like my cooking client Harvest Eating), it’s essential to add a print stylesheet.

For everyone else, it’s just a good practice to have your site look well printed. Luckily, it’s pretty easy.

The custom.css file you use to design your Thesis site only defines styles for the web, so when you print those are already gone. The main thing we’ll use the print stylesheet for is hiding things we don’t want showing up, like the menu and sidebars.

Create the Print Stylesheet

Go into /themes/custom and create print.css.

Now you can start writing your print-specific styles. For everything you want hidden, add it to {display: none;}.  Here’s the print stylesheet I used for Harvest Eating:

.custom #submenu, .custom #header .left, .custom #header .right, .custom #header .menu, .custom #sharethis_0, .custom #print, .custom #tweetmeme_button, .custom .video, .custom #idc-container, .custom .prev_next, .custom #sidebars, .custom #footer-recipes, .custom #footer {display:none;}
.custom #print-logo {float: right;}

See this post by A List Apart for some great print stylesheet tips.

Add the Print Stylesheet to Thesis

Once your print stylesheet is done, stick this in custom_functions.php to add it to the site.


/* Print Stylesheet */
function print_stylesheet() {
echo '<link type="text/css" media="print" href="' . THESIS_CUSTOM_FOLDER . '/print.css" rel="stylesheet" />';
}
add_action('wp_head', 'print_stylesheet');

Print Logo

You’ll also notice I have a #print-logo at the bottom of my print stylesheet. We wanted the Harvest Eating logo to show up on any recipes that were printed out, but we didn’t want to use up the customer’s color ink on it. So I created a black-and-white version of the logo, added it to the top of the header, and hid it using the custom.css stylesheet. So when the page is printed (and so the custom.css stylesheet isn’t being used), it shows up.

In custom_functions.php:


/* Logo at top on printed page */
function print_logo() { ?>
<div id="print-logo"><img src="<?php bloginfo('template_url');?>/custom/images/logo-bw.jpg" /></div>
<?php }
add_action('thesis_hook_before_header','print_logo');

In custom.css

.custom #print-logo {display: none;}

All Thesis Tips:

Bill Erickson is a WordPress Consultant who builds custom websites using WordPress as a CMS and Thesis as a framework. He’s a cofounder and resident of The Creative Space, and a cofounder of the BIL Conference (the open analog to the TED Conference).

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

{ 10 comments… read them below or add one }

Lars Tong Strömberg February 5, 2010 at 10:17 pm

How have you fixed the "print this page" links at the articles at Harvest Eating? Just below the "Share this" buttons on each page?

Reply

Bill February 9, 2010 at 12:20 pm

I added the following code to my custom_functions.php file:

if (window.print) {
document.write(' '
+ '');
}
// End -->


Just put that inside a function and use a hook to place it where you like.

Reply

Dominic Z. February 21, 2010 at 10:29 pm

For me it doesn't work, I tried everything.
I added the code, chose option to use custom stylesheet, but the printing preview is the same as before.

Reply

Corp Warrior March 1, 2010 at 1:32 pm

It's definitely there. It probably can't be seen because of security settings. Try right click and 'save as' and then open it in notepad and you will see the content of the file.

Reply

Bill Erickson March 1, 2010 at 2:03 pm

I get \”File Not Found\” when I try to download it.

If it is there, there's a good chance that the security settings that won't let me see it are what's causing it not to work. If I can't download it, your vistors' browsers can't download it.


Bill Erickson
Wordpress Consultant
http://www.billerickson.net

Reply

Corp Warrior March 1, 2010 at 2:20 pm

Hmm. That's weird, when I right click on this link:
http://www.corpwarrior.com/wp-content/themes/thes...
and choose "Save As" I can download it without any problems.
About the security settings, I jut mentioned them as an idea, I don't really know the real reason.

BTW. Does the option "Subscribe to Replies" on your site works properly? I'm asking only because I haven't got any mail about reply being made on this comment although I had subscribed to the replies. I saw your reply accidentally. I thought you never answered.
Tnx.

Reply

Bill Erickson March 1, 2010 at 2:26 pm

When I right click and try to save that, it saves the 404 page. I don't know what's causing it, but it's not a problem I've seen before. I'd talk to your host about it.

I'd assume Subscribe to Replies works, but I've never used it before so I can't confirm. If it doesn't work I can contact Intense Debate (the developers of the commenting system) and see what the problem is.

Thanks


Bill Erickson
Wordpress Consultant
http://www.billerickson.net

Reply

Corporate Warrior March 2, 2010 at 11:24 pm

Maybe I need to change the permission rights on some of the folders and files (CHMOD them), will look into it.
About the reply system, it's really great, I just installed it on my blog. I'm not sure if I confirmed the subscription, so maybe it's even working just fine.
I would like to ask you just one more question. I hope I'm not too pushy, but I'm kind of a new to blogging and don't know all the tricks yet. :)
How can I add the tags on sidebar, but that they look like on this site for example: tags like on these two sites for example: hxxp://thetechedition.com/ , hxxp://dmzwarez.info/
I installed some plugins (simpletag or something like that) and I tried with others as well but can't seem to get it too look similar. And I've seen dozens of blogs using nice similar tags.

Reply

Bill Erickson March 3, 2010 at 1:18 am

Just go to Appearances > Widgets and drag the Tag Cloud widget to the sidebar.


Bill Erickson
Wordpress Consultant
http://www.billerickson.net

Reply

Dominic Z. March 12, 2010 at 4:48 pm

Sorry for late reply. Just wanted to say thank you for your answers.

Reply

Leave a Comment

Previous post:

Next post: