Quick Tip: Adding a Simple Print Stylesheet to WordPress

Adding a print stylesheet to your Wordpress site is a wise move. The environment will thank you for applying this article to your website. It's such a simple feature to implement, and most people just overlook it. I'll show you how easy it is to add a simple print stylesheet to your Wordpress site. I'm going to give you a great foundation of one you can use in your site immediately, and show you a few tips so you can take it to the next level.


Step 1. Implementing a Print Stylesheet

You'll need to update your theme's header.php file to let it know that the stylesheet we'll be updating will be used for printing as well. Open up header.php, look for:

We need to update the media attribute to include print. Screen is telling the browser "This is the stylesheet you should use to know how to display the elements within the browser". We need to tell it "You can also use this stylesheet when the user is printing". So now it looks like:

Next, open up your stylesheet, style.css. At the end of the document, add:

It's key that the code is at the bottom of the stylesheet to be sure that your screen styles don't inherit styles we're using for printing and so that the printing styles won't be overridden with the styles of your site. After that's done, create a file in the same directory with the name print.css. This is where we'll add all our style for printing.

Adding a print stylesheet to WordPress

Step 2. Adding the Print Styling

Below is a modified version of the print style for Wordpress' Default theme "TwentyTen". A lot of websites share these same elements, so there's no need to reinvent the wheel with developing one. What I'm going to do is break down the key elements, so you know why they were included and what styles you should be on the look out for to add it to your own custom elements.


Step 3. Understanding the Print Styling

Wrap Your Tags for Print

First, you should notice how all your print styles are wrapped inside:

All objects that correspond to the print functionality are styled between these brackets. Should you add any style, be sure it's within these brackets. If it's outside, CSS won't know any better and will assume it's part of the screen media.

Make Everything Black and White

This is one of the key elements to creating a print style. Typically, anything print friendly should not have a background to it, and all coloring should be black and white.

Block Your Elements and Make Sure They Don't Overlap

These are basic styles that are making sure everything shows up one on top of the other. Clearing it will make sure everything in #wrapper will fall under the previous element, and anything after it will fall after the wrapper so that things don't get shoved beside one another. It shouldn't have a float and the position should remain relative. What this will do is make sure the content reads left to right, and that no objects will overlap one another; it will be one flowing document.

Use Borders and Spacing for Separation

You'll notice a few properties that actually style the element throughout the print stylesheet. These are absolutely acceptable. A lot of times, color will separate elements in a design. Since everything is in black and white, it is hard to do that. So things like adding a black border to the bottom of an element, and adding some space underneath it will help clearly separate them.

Keep Font and Line Size in Mind

It's a great idea to consider the text size of the content you're printing. The size you see on the screen compared to what eyes are able to read are very different. Consider a smaller font size, 14 pt is plenty I feel. I may consider even going smaller than that. Having a line height that helps the content flow is also very helpful. Be sure to give some space between your lines so that the printed text isn't illegible. Also, giving titles a larger font size will help to distinguish them from the content.

Hide Unnecessary Elements

This will be one of your most used element attributes. 'display:none' is going to hide the element entirely. The printed page will treat it like it wasn't even there to begin with, so if you hide all your images it won't show a blank spot where they would be normally; the element will be taken completely away from the layout and the next available content will render. I use this a lot for unnecessary elements to include in my print like images, navigation, and sidebars.

Take the Full Page Width

This element is making sure that all your elements that wrap the content of the page have a width of 100% so that they'll take up the entire available margin on the printed document. Sometimes designers will set a width of 900px or the likes there of, which would only allow print to happen in a 900px area.

Elements are Allowed Different Emphasis in Print

In the screen stylesheet, this would be the left chunk of content. It would have a sidebar to its right. You'll notice now that it no longer has a width limited to that space, it will take up the full available margin on the printed document. It has a width of 100% and the sidebar will no longer be able to fit beside it. In fact, the sidebar should have a display:none somewhere in the print stylesheet. There's also a margin attribute that will separate it from the content around it so that it will stand out.

Find Out Which Images You Can Remove

This is a great example of hiding images that have the ID of "wpstats". You can create your own class called hideInPrint to add to images that you want to remove when printing. The code for that would look like:


Conclusion

This article is just a foundation - you can obviously add your own unique brand styles to this to create a customized print style. Here, we've shown you the elements you should keep in mind when implementing a print stylesheet into your own project; The rest of the styling will be up to you in your own project! Knowing the thought behind "why" certain attributes were used, will help your insight as to what your project will need.

Tags:

Comments

Related Articles