WordPress.org

Forums

CleanPrint
Shortcode doesn't work (8 posts)

  1. Treebeard
    Member
    Posted 2 years ago #

    I followed the instructions by adding the code to my template file:

    <?php add_shortcode('cleanprint_print_button', 'get_cleanprint_print_button');
        function get_cleanprint_print_button() {
           if( function_exists('cleanprint_add_print_button') ){
              return cleanprint_add_print_button();
           }
        }
    ?>

    and the shortcode to the page I want the buttons on:

    [cleanprint_print_button]

    but the page just shows the shortcode as it appears in the editor, no buttons. The buttons appear if I active ALL PAGES to have the buttons, but I only want 1 page to have the buttons.

  2. johncadams
    Member
    Plugin Author

    Posted 2 years ago #

    If added to functions.php file you should not need to wrap the code in a php header, (<?php ... ?>) the functions.php file usually has already declared it.

    Also make sure you are running WP 2.5 or later.

  3. Treebeard
    Member
    Posted 2 years ago #

    As you can see above, it is wrapped in a php header. But why would I add it to functions.php? I didn't see that in the documentation anywhere. I added the code to the template within the loop, right above the_content, like this:

    <?php add_shortcode('cleanprint_print_button', 'get_cleanprint_print_button');
        function get_cleanprint_print_button() {
           if( function_exists('cleanprint_add_print_button') ){
              return cleanprint_add_print_button();
           }
        }
    ?>
    
    <?php the_content(); ?>

    I thought that's what you were supposed to do, I didn't see any documentation about it. If I added it to the functions file, then where would that button go? I need to place it where I want it, not on all pages, only on the 1 page, so that's why I added it to the template file I created for this page.

    Running 3.4.2...

  4. johncadams
    Member
    Plugin Author

    Posted 2 years ago #

    Normally the functions.php file starts the php syntax (look at the top of the file) and never closes it. Therefore you don't add the php delimiters and simply append the code to the bottom.

  5. Treebeard
    Member
    Posted 2 years ago #

    I just didn't realize the code was supposed to be in the functions file. Do you know how to show a print button only on a specific template?

  6. johncadams
    Member
    Plugin Author

    Posted 2 years ago #

    I suppose if you moved the code to the template file (without <?php ) that is included by functions.php that may work (give it a try). This is really a general shortcode question and nothing specific to CleanPrint.

  7. johncadams
    Member
    Plugin Author

    Posted 2 years ago #

    BTW this topic isn't a review and should move to the support forum.

  8. Treebeard
    Member
    Posted 2 years ago #

    Yea I know right! That was really weird, when I clicked on a rating, it automatically took me to that page and I didn't realize it was a Reviews tab (was really late), so just started typing out my question. I apologize, I don't know how to move it though. Maybe it can be deleted? I checked here, and there's no option to delete a review once it's posted (that I can see).

    Anyway, I already tried the template php. Normally that works, but that's why I posted the question, because it's not working.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.