WP Print Friendly for WordPress
Extends WordPress’ template system to support printer-friendly templates for posts, pages, and custom post types. Uses WP standard template naming to support templates on a post-type basis. Supports printing paged posts on single page. Adds nice URLs for printer-friendly pages.
The plugin comes bundled with a basic print template that will likely suit many needs.
To take advantage of its templating capabilities, add a file named wpf.php to your theme. From there, you can use any existing WordPress functions to generate your print view. To create a custom print template for your homepage, add wpf-home.php to your theme. From there, standard WordPress template naming conventions are followed, so wpf-[custom post type name].php or wpf-[custom taxonomy name].php would be invoked for your custom post type and custom taxonomy, respectively.
To add a print link to your templates, you can either let the plugin add it automatically via the settings available under Options > WP Print Friendly, or you can use this function: wpf_the_print_link( $page_link, $link_text, $class, $page_link_separator, $page_link_text );. The optional parameters are as follows:
- $page_link: Set to true to include a link to the current page of a paged post. To exclude this link, set to false.
- $link_text: Sets the text for the print link for the post’s full content. Defaults to “Print this post.”
- $class: CSS class for the print links. Defaults to “print_link.”
- $page_link_separator: Specifies how the full-post and page-specific print links should be separated. Defaults to ” | “.
- $page_link_text: Sets the text for the page-specific print link. Defaults to “Print this page.”
- $link_target: If set to “new”, print links will open in a new window.
Hi,
Is there a way to replace text button to an printer image with your plugin?
Emil,
The plugin doesn’t have that feature built in, but with an icon and a bit of CSS, it can easily be added. I’ll consider adding that capability to a future version of the plugin.
Erick
It would also be cool to have justification options, so that the link or icon could be left, right or center…. I tend to look to the right for that stuff, and it is on the left, where I kind of lose it in the clutter.
I downloaded the plugin and installed. Now when I click on the print link, Im getting a 404. What am I doing wrong? Thanks for your help!
After activating the plugin, did you refresh your permalinks by going to Settings > Permalinks and clicking the Save Changes button? If not, you need to do so.
If you’ve done that, can you provide more information about where you’re encountering the 404 error? Does it happen only for certain content (posts, pages, just the homepage, etc) or in certain areas of the site?
Hi, Erick – “use this function” is a little bit too complicated for WP newbies
How do I use it – could you give the complete code please? Do I have to put in in some brackets like a shortcode? Does it work in pages, articles and/or temlates? And will your plugin print the content of custom fields?
Thanks for any help – many greetings, Gabi
Gabi,
You would place the code in your theme files. For example, if you need just a basic print link, you can add
<?php wpf_the_print_link(); ?>to your theme’s loop to add print links for each post in the loop. If you needed to change the default link text to read Print this article, you would add<?php wpf_the_print_link( false, 'Print this article' ); ?>. If you have paged posts in your WordPress instance and would like print links for each page of the paged post, you would add<?php wpf_the_print_link( true ); ?>.Hope this helps,
Erick
Hi, Erick – thanx for your quick answer! Unfortunatly the code does not work – I get “Fatal error: Call to undefined function wp_the_print_link()” when I add it to single.php… Automatic insertion works, though – but I specifically want to put the print link within a special meta box of my blog…
I also noticed that the plugin doesn’t print custom fields that belong to posts.. Is there maybe a way to change that?
Greetings and thanx in advance for any assistance – Gabi
Found the first answer myself : It’s NOT wp_the_print_link – the name of the funktion should be wpf_the_print_link
Still searching how to include the content of custom fields and how to open the print version in a new tab/window, though…
Many greetings – Gabi
Gabi,
I’ve updated the documentation to reflect the correct function name. Whenever you add plugin functions to your theme, it’s always a good idea to include a
function_existscheck to ensure that if, either intentionally or accidentally, a plugin is disabled, your site continues to function. Simply addingif( function_exists( 'wpf_the_print_link' ) )before the reference to the print function should do the trick.To include post meta, you’ll need to create your own print template in your theme. You can use the
default-template.phpfile included with the plugin as a starting point. You should copy that file into your theme and rename itwpf.php. After doing so, the plugin will load that file when rendering print-friendly views, rather than the default template. You can then add the necessary post meta.Erick
Thanx, Erick – I did create my own wpf-php and it works fine.
One last question though: How do I open the print file in a new tab or window, so that the regular blog does not disappear? If the print version replaces the regular view users will have to use the browser’s back-button to continue reading my blog which is awkward…
Many greetings – Gabi
Currently, that isn’t an option using the
wpf_the_print_linkfunction. I’ve noted the suggestion and will include that in a future release. In the meantime, and if you’re feeling a bit adventurous, you can build your own print link using the functionwpf_get_print_url(). If used within the loop, no parameters are needed; the function simply returns the URL for the print-friendly version of the current post within the loop. If used outside of the loop, the first argument should be set to the post ID.Erick
Sorry to bother you again, Erick – but I don’t know any PHP
When I construct a link like
<a href="” target=”_blank”>Open print version in new window
within the loop (single.php) it opens the REGULAR page in a new window. I noticed that the >>&print=all<< part is missing, but when I add it like this
<a href="&print=all” target=”_blank”>Open Print version in new window
the URL part (?p=123) disappears. So I still can’t open the print version in a new window. What’s wrong with my sorry attempt to code PHP?
Greetings from Germany – Gabi
Sorry to bother you again, Erick – but I don’t know any PHP
When I construct a link like
<a href="" target="_blank">Open print version in new windowwithin the loop (single.php) it opens the REGULAR page in a new window. I noticed that the >>&print=all<< part is missing, but when I add it like this
<a href="&print=all" target="_blank">Open Print version in new windowthe URL part (?p=123) disappears. So I still can’t open the print version in a new window. What’s wrong with my sorry attempt to code PHP?
Greetings from Germany – Gabi
Oh dear – the code parts disappear. Another try:
The first link looks like this (without the stars, of course)
*<*a*href=*"**target=”_blank”*>*Open print version in new window*
The second part like this:
*<*a*href=*"**?*print*=*all” *target=”_blank”*>*Open Print version in new window**
Gabi,
Version 0.3.2, which should be available within the hour, adds an option to open print links in a new window. To do so, the final argument for
wpf_the_print_linkshould be set to new. Omitting the argument will cause the print view to open in the same window.Erick
Hi ,
).
I have website with subpages like /page1/page2
your plugin works on /page1/print but unfortunately doesn’t work on /page1/page2/print , i think problem lies in rewrite rules which don’t take in to consideration that something might be before “slug”,. Would be glad if you could help maybe i am doing something wrong (btw yes i did click on save changes
thx
Firegnom,
I’m working on a solution to this problem and hope to release an update in the very near future. Thanks for reporting this problem.
Erick
Wow – great service, thank you!
Hi,
I have a requirement like to print the content of post only. Is there any chance to do it. I have impressed by you plugin. But Its not reached to my requirement. Could you please help me out.
Sateesh,
You can include a custom print template in your site’s theme and modify it to fit your needs. I suggest starting by copying the default print template from the plugin folder to your theme directory, renaming the file wpf.php, and modifying it as needed.
Erick
This plugin doesn’t seem to work for pages which are not @ root level. If there is a page with a parent, it won’t open the print preview for it.
Poxy,
I’m working on a solution to this problem and hope to release an update in the very near future. Thanks for reporting this problem.
Erick
Hi, Erick – after I activated permalinks within my blog, I get 404-errors when trying to print pages and articles (it did work before). I de-activated wp print friendly, activated it again and hit “save changes” on the permalinks page – to no avail. What elso could I try?
I’m using the variable wpftheprintlink within single.php and the generated print link looks something like http://www.my-domain.de/name-of-article/print – is something wrong with that?
Greetings from Germany – Gabi
Gabi,
Version 0.4 should fix this problem.
Erick
Erick,
I think I’ve found another corner case in which Print Friendly fails.
I’m using a really neat plug-in named embed, a tool that lets you display several “child” posts together within either a page or a “parent” post (davidtyler.we.bs/page/web/wordpress-plugin-embedded-posts).
When a composite page with embedded posts is displayed, the PF link displays a clone of the page with all page and browser furniture, not the PF version.
Cheers,
Art
Art,
Version 0.4 may correct this problem, but it’s also possible that you’ll need a custom template for use with this plugin. What is the name of the plugin you’re using?
Erick
I have a client that was about to purchase your ad-free version however we are running in to some cross-browser compatibility issues. If you can respond via email, I would like to link you to the site to review a sporadic issue between certain posts. Thank you!
Thanks for the plugin! Question though, and please excuse me being a complete newbie who doesn’t know much about coding. I was able to add a print option, but when i tried it, it doesn’t let me print individual posts, it only lets you print it as one long page – is there a way to separate it so people could print each individual post? Hope that makes sense. If you look at my site you will see what I mean. Thanks!
I have this issue too. “Print this entry” and “Print this page” print all ten entries on each page. If I open a single post then it only prints that entry, like it should. Would love a fix for this. Thanks!
Version 0.4 fixes this problem.
Erick
hi i need help. the plugin works… but not really. i cant seem to limit the plugin to just appear on post pages. i uncheck the “display automatically on pages” box but they still appear on both pages and posts. thanks in advance for your help
Mark,
Version 0.4.1 fixes this problem.
Erick
GREAT WORK! Mr. Erick that’s exactly I needed. But, still have the same issue, with page1/page2… Mr Erick or some of the users get solved? Please give us a light about! thanks ^_^
Version 0.4 adds full support for pages, namely child pages.
Erick
Hey Erick,
First of all – awesome plug-in! The functionality and method you used is exactly what I’m looking to plug in to my current project. I’m having a small problem though: using a custom post type, the rewrite rules and link generation work like a charm, but the /post-type/post-name/print url doesn’t seem to be calling the wpf-post_type.php template at all. I’ve crawled over the code a bit, and can’t immediately find why this should be. Any ideas?
Thanks!
Dan,
If version 0.4 doesn’t fix this problem, please let me know.
Erick
“To take advantage of its templating capabilities,” you write, “add a file named wpf.php to your theme. From there, you can use any existing WordPress functions to generate your print view. To create a custom print template for your homepage, add wpf-home.php to your theme.”
I am using WordPress and I am completely lost here. I have checked and have found “WP Print Friendly is activated.” When I go to settings to find “Options,” there is no sub heading. Now, I’m really confused. I doubt if I need to say that I am a novice user (smile). I just want my blog viewers to be able to print a recipe from my site.
Harold,
Version 0.4 fixes numerous bugs, so I’d start by upgrading to that.
After doing so, go to Settings > WP Print Friendly and make sure that
Automatically add print links based on settings below?is set toYes. If you are using a plugin to create your recipes, you may need to check additional options underDisplay automatically onfor my plugin to interact with the recipes plugin. Otherwise, if you’re using posts or pages, ensure that those options are selected underDisplay automatically on.Erick
thank you for this plugin but I would ask a question about target frame in hyperlinks. now every think is ok bu the print page is open in the same page. in settings panel I select new page it doesnt change anything.
how we can make it manually.? it is so important for me can you help me…
Version 0.4 should fix many problems with the print links themselves.
I’ll note your request for popup print windows for a future version; the drawback to them is that many browsers will block them without prior approval.
Erick