# WP-Print Contributors: GamerZ Donate link: https://lesterchan.net/site/donation/ Tags: print, printer, printable, print button, print link Requires at least: 6.8 Tested up to: 7.0 Stable tag: 3.0.0 Requires PHP: 8.2 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html Displays a printable version of your WordPress blog's post/page. ## Description WP-Print adds a print link to your posts and pages. Following it gives the reader a clean printable document: your content, its comments if you want them, and nothing else — no theme, no sidebar, no navigation. Every link in the printed article is numbered and its URL listed at the end, because a reader holding a sheet of paper cannot click anything. ### Features * A printable version of any post, page or custom post type, at `/your-post/print/` * Every link footnoted with a number and listed at the end of the document * Optional comments, images, embedded video and featured image * `[donotprint]` for content that should never reach the printed page * One stylesheet in both text directions, with a dark mode for reading before printing * Templates and styles you can override from your theme ### Donations I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks, I will really appreciate it. If not feel free to use it without any obligations. ## Installation 1. Install and activate the plugin. 1. Re-save your permalinks at `WP-Admin -> Settings -> Permalinks -> Save Changes`, so the `/print/` endpoint is registered. **The printable page returns a 404 until you do this.** 1. Add the print link: type `[print_link]` into a post, or call `print_link()` in your theme. Usage below covers both. 1. Templates and options are at `WP-Admin -> Settings -> WP-Print`. ## Usage Add the print link to your theme inside the loop, wherever you want it to appear: ~~~ if ( function_exists( 'wp_print' ) ) { print_link(); } ~~~ `print_link( $post_text, $page_text, $display )` takes whether to print or return as its third argument. The first two used to override the link text and no longer do anything: the link is one HTML template on the settings screen, under Templates, and `%POST_TYPE%` in it becomes Post, Page or the name of whatever custom post type is being printed. They stay in the signature so that a theme still passing them keeps working. If you would rather not have the link on every post, leave your theme alone and type `[print_link]` into the one post or page that needs it. ### Shortcodes * `[print_link]` — the print link, in the post or page it is typed into. * `[donotprint]Not for paper[/donotprint]` — the enclosed content is dropped from the printable version and left alone everywhere else. WP-Email honours the same tag, so text you exclude from print is excluded from email too. ### Template Tags * `print_link( $post_text, $page_text, $display )` — the print link. Only the third argument does anything. * `print_content( $display )` — the post content, prepared for printing. * `print_comments_content( $display )` — the current comment's content. * `print_categories( $before, $after )` — the categories, each wrapped in your markup. * `print_comments_number()` — the comment count as a sentence. * `print_links( $heading )` — the collected list of URLs. * `print_can( $type )` — whether one of the options is on. * `print_disclaimer()` — the disclaimer or copyright line. ### The Print Link The print link is one HTML template, at `WP-Admin -> Settings -> WP-Print -> Templates`. Three placeholders are replaced when it is rendered: * `%PRINT_URL%` — the URL of the printable version. * `%POST_TYPE%` — what is being printed, in the singular: Post, Page, or the name of a custom post type. * `%PRINT_ICON%` — the printer glyph, as an inline SVG that takes its colour from your theme. Anything else is left in the markup exactly as you typed it. Restore Default Template puts the shipped one back. ### Custom Template WP-Print loads `print-posts.php`, `print-comments.php` and `print-css.css` from your theme's directory if they exist, child theme first, then parent, then the copies bundled with the plugin. Copy one into your theme to restyle the printable page without losing the change on upgrade. The bundled copies moved in 3.0.0 — the templates are in `includes/` and the stylesheet is `css/wp-print.css` — but the names your theme overrides them with are unchanged. ### Filters * `wp_print_capability` — the capability the settings screen requires. Defaults to `manage_options`. * `wp_print_allowed_html` — the tags the printed document may carry, in `wp_kses()` form. Add to it if a block on your site prints markup the default list does not cover. ## Frequently Asked Questions ### How do I add the print link to my theme? Open `wp-content/themes//index.php`, and single.php, page.php and any other template that runs the loop. Find `` and add this anywhere below it: ~~~ if ( function_exists( 'wp_print' ) ) { print_link(); } ~~~ ### The print link 404s Re-save your permalinks at `WP-Admin -> Settings -> Permalinks`. WP-Print adds a `/print/` endpoint, and WordPress only writes the rewrite rules out when that screen is saved. ### How do I keep part of a post off the printed page? Type this into the post: ~~~ [donotprint]Text within this tag will not be displayed when printing[/donotprint] ~~~ The enclosed text is dropped from the printable version and shown as normal everywhere else. ### Can I change how the printed page looks? Yes, two ways. Copy `print-css.css` into your theme to replace the stylesheet outright, or set any of the custom properties the bundled sheet uses — `--wp-print-font-family`, `--wp-print-font-size`, `--wp-print-line-height`, `--wp-print-text`, `--wp-print-background`, `--wp-print-rule` and `--wp-print-gap` — to retune it without forking the file. ### Is the print icon still an image I can choose? No. The two bundled GIFs are one inline SVG that takes its colour from your theme and stays sharp at any size, so there is nothing left to choose between and the Print Icon setting is gone. ### Where did Print Text Link For Post, For Page and Print Text Link Style go? They are one HTML template, on the Templates tab. The style dropdown offered three fixed markups and a custom template; the three were templates too, written in PHP rather than in the box, so all four are now the box. Write the wording you want into it and use `%POST_TYPE%` where the words Post or Page used to differ. Your existing settings are converted on upgrade. ### What replaced %PRINT_TEXT%? Nothing, because there is nothing left for it to stand for: it inserted whichever of the two link labels applied, and the wording now lives in the template itself. Use `%POST_TYPE%` for the part that changes between a post and a page. A template still containing `%PRINT_TEXT%` renders it on the page as written, which is deliberate — it is how you find the ones that need editing. ## Screenshots 1. Settings -> WP-Print, choosing what the printable version carries 2. The Templates tab, holding the markup of the print link 3. The print link in a post, placed with the shortcode 4. The printable version, without the theme around it ## Changelog ### 3.0.0 * FIXED: A password-protected post printed its featured image. The body, the comments and the comment count were all withheld, but `get_the_post_thumbnail()` makes no password check of its own — which is why every classic core theme makes the test itself, and this template replaces the theme's, so nothing was making it * FIXED: "Print Images" and "Print Videos" were defeated by a newline. The patterns had no `s` modifier, so an `` tag written across two lines, or an `