Title: Print Button -&gt; print.css
Last modified: August 22, 2016

---

# Print Button -> print.css

 *  Resolved [blueshark](https://wordpress.org/support/users/blueshark/)
 * (@blueshark)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/print-button-printcss/)
 * Hi there,
 * for each page I want to add a print button. This button makes the site reload
   with other style sheets, so that is fine for printing.
 * I am using post name permalink setting, so a link to a page or post looks like
   [http://my-url.de/sample-post/](http://my-url.de/sample-post/):
    `<a href="<?
   php print get_permalink().'?print=true'; ?>" title="Printversion">...</a>`
 * As a fist solution I added just a ?print=true to the link and then check for 
   $_GET[‘print’]:
    `<?php if( !isset($_GET['print']) || $_GET['print']!=true ||!(
   is_single()||is_page()) ): ?>...`
 * This works fine so far, but it is not a clean solution. When changing the permalink
   structure this might not work, since it will end in somethink like [http://my-url.de/?p=123?print=true](http://my-url.de/?p=123?print=true)
 * So what might a nice solution for that issue?
 * Thanks
 * Blueshark

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Ryan Sechrest](https://wordpress.org/support/users/sovereign/)
 * (@sovereign)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/print-button-printcss/#post-5628772)
 * Have you considered using something like a [print stylesheet](http://www.smashingmagazine.com/2011/11/24/how-to-set-up-a-print-style-sheet/)?
   That way, if the print button is pressed in the browser, it will also print nicely
   and doesn’t require a page reload.
 *  Thread Starter [blueshark](https://wordpress.org/support/users/blueshark/)
 * (@blueshark)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/print-button-printcss/#post-5628878)
 * I do have a print stylesheet. But I prefer also a preview, so that the user can
   see what he is printing. So I want to reload the page with the print stylesheet.
   This stylesheet is triggered with the ->print<- option.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/print-button-printcss/#post-5628880)
 * You basically need to check for an existing ‘?’ in the permalink to decide to
   add a `'?print=true'` or a `'&print=true'` to the URL. I wouldn’t call the code
   needed to do this “nice and clean”, but it is necessary.
 * You could use [add_query_arg()](http://codex.wordpress.org/Function_Reference/add_query_arg)
   to add your print query arg. This hides the necessary code in core so at least
   your code is nice and clean 🙂
 *  [Ryan Sechrest](https://wordpress.org/support/users/sovereign/)
 * (@sovereign)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/print-button-printcss/#post-5628881)
 * OK, what I would do then is:
 * 1. [Add a new query var in WordPress](http://codex.wordpress.org/Plugin_API/Filter_Reference/query_vars)
 *     ```
       function query_vars($query_vars) {
       	array_push($query_vars, 'print');
       	return $query_vars;
       }
   
       add_filter(
       	'query_vars',
       	'my_query_vars'
       );
       ```
   
 * 2. Add a function to build the print permalink
 *     ```
       function get_print_permalink($permalink) {
       	$url = parse_url($permalink);
       	if ($url['query'] === '') {
       		echo $permalink . '?print=true';
       	} else {
       		echo $permalink . '&print=true';
       	}
       }
       ```
   
 * 3. [Retrieve query var value from WordPress](http://codex.wordpress.org/Function_Reference/get_query_var)
 * This is how you’d check whether the query var is set or not:
 * `get_query_var('print, 'false');`
 * It will return false if it doesn’t exist or true if it’s set to true.
 * The code above is untested, so let me know if you’re running into issues.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Print Button -> print.css’ is closed to new replies.

## Tags

 * [css](https://wordpress.org/support/topic-tag/css/)
 * [print.css](https://wordpress.org/support/topic-tag/print-css/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 4 replies
 * 3 participants
 * Last reply from: [Ryan Sechrest](https://wordpress.org/support/users/sovereign/)
 * Last activity: [11 years, 4 months ago](https://wordpress.org/support/topic/print-button-printcss/#post-5628881)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
