Print Button Shortcode
Adds a [print_button] shortcode that places a button visitors can click to print the current page, useful for recipes, guides and forms.
Opens WPIDE on
Code
add_shortcode( 'print_button', function ( $atts ) {
$atts = shortcode_atts( array( 'label' => 'Print this page' ), $atts, 'print_button' );
return '<button type="button" class="wp-element-button wpide-print-button" onclick="window.print();">' . esc_html( $atts['label'] ) . '</button>';
} );
Notes
Change the label with [print_button label="Print this recipe"].
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.