I'm trying to use an existing plugin in order to make my posts print friendly. I haven't got any support from the plugin developer. I think I have narrowed down the script to the function that places the 'Print' text in the posts.

Problem is that this plugin places the 'Print' button automatically. But I would like to place it in a template and prevent the automatic placement.

This is the code that does the job of placing the print button. Can someone suggest a modification so that the following script 1. DOES NOT place the 'Print' button automatically. 2.What would be the function to call/place in my single.php page.

if ( !$_GET['print'] == 1  ) {
    add_filter( 'the_content', 'printme_add_link' );

function printme_add_link( $content ) {
    if ( is_singular() ) {
        $printme_options = get_option( 'printme_options' );
        $print_stub = $printme_options['print_text'];
        wp_enqueue_script( 'jquery' );
        wp_register_script( 'printme', plugins_url( '/printme.js', __FILE__ ), false, '1', true );
        wp_enqueue_script( 'printme' );
        $link = add_query_arg( 'print', '1', get_permalink() );
        $content = '<a href="' . $link . '" target="_blank">' . $print_stub . ' </a>' . $content;
        return $content;


add_action( 'template_redirect', 'printme', 5 );
function printme() {
    if ( $_GET["print"] == 1 ) {
        include( plugin_dir_path(__FILE__) . 'print.php' );

remove_filter( 'the_content', 'printme_add_link' ) will prevent the link from being placed. You can just call printme_add_link() in your template to generate the print button. Alternately, you can just add_query_arg( 'print', 1, get_permalink() ) and use that as the link if you would prefer to do the link some different way.

| improve this answer | |
  • I put in the remove_filter( 'the_content', 'printme_add_link' ) right after the function printme_add_link( $content ) so now the 'Print' doesn't show. However adding the printme_add_link() or the alternative doesn't display anything at all. P.S: Had to use <?php printme_add_link($content); ?> because without $content I get the 'Missing argument 1 for printme_add_link()' error in the output – Sledge81 May 19 '12 at 11:14
  • You should be putting it in your own files, not in the plugin files. If you put it in plugin files, then it will break on update, whereas if you put it in your own files you can happily update the plugin. If you're gonna modify plugin files, just physically remove the add_filter() for the function. – mor7ifer May 19 '12 at 11:15
  • Ok. So I put in remove_filter( 'the_content', 'printme_add_link' ); into my functions.php in single.php when I use <?php printme_add_link(); ?> I get this error: Missing argument 1 for printme_add_link(), called in themes/custom/single.php on line 41 and defined in /public_html/wp-content/plugins/print-me/printme.php on line 16 and when I use <?php printme_add_link($content); ?> nothing shows up (neither the print text or an error message) – Sledge81 May 19 '12 at 11:23
  • Use printme_add_link( '' ). It's appending a string to the given content, so that will return nothing but the string. – mor7ifer May 19 '12 at 11:28
  • 1
    Are you actually echoing it? All printme_add_link() does is return, if you want echo, then use echo. – mor7ifer May 19 '12 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.