PDF Creation Station – hard code PDF link into theme

-- Download PDF Creation Station - hard code PDF link into theme as PDF --

This post is for users of Kalin’s PDF Creation Station WordPress Plugin who want PDF files automatically generated for pages/posts, but want more control over the placement/appearance of the link or want better performance over the automatic link generation method.

First, get into your theme files. You can hit ‘Editor’ under ‘Appearance’ in your WordPress admin which will allow you to edit your theme files directly. I’ve had issues with this, however, with mysterious bugs creeping into my code. I recommend using FTP to get your theme files, making a backup, then editing and re-uploading them.

Find the file you want to add the link to, probably sidebar.php, header.php or footer.php, or something like that, then add this code:

     echo '<a href="http://my-domain/wordpress/wp-content/plugins/kalins-pdf-creation-station/kalins_pdf_create.php?singlepost=po_' .$post->ID .'">Download this post as PDF</a>';
          echo '<a href="http://my-domain/wordpress/wp-content/plugins/kalins-pdf-creation-station/kalins_pdf_create.php?singlepost=pg_' .$post->ID .'">Download this page as PDF</a>';

Then replace ‘my-domain’ with your own domain. If you have a non-standard WordPress configuration you will need to look at the rest of the urls to make sure they match your directory structure.

This will add the link on any page or post, but show nothing on other pages.

If you are adding this to your single post or page templates, or inside “the loop” instead of into a footer, header or sidebar, you theoretically won’t need the check if it’s a page or post. Use this on the post template:

     echo '<a href="http://my-domain/wordpress/wp-content/plugins/kalins-pdf-creation-station/kalins_pdf_create.php?singlepost=po_' .$post->ID .'">Download this post as PDF</a>';

And there’s only  a small change for use on the page template:

     echo '<a href="http://my-domain/wordpress/wp-content/plugins/kalins-pdf-creation-station/kalins_pdf_create.php?singlepost=pg_' .$post->ID .'">Download this post as PDF</a>';

Now that you’ve hard-coded your link, you can optionally turn off the automatic link adding functionality in the plugin to get a slight performance increase. It won’t make a huge difference and you will need to re-do this every time I upgrade the plugin so it may or may not be worth your time.

FTP  into your plugins directory and find /kalins-pdf-creation-station/kalins-pdf-creation-station.php (or use the editor in your WordPress admin panel). Scroll to the very bottom of the file and find the line,

add_filter("the_content", "kalinsPDF_content_filter" );

Comment the line out so it looks like:

//add_filter("the_content", "kalinsPDF_content_filter" );

Commenting out this line will prevent the plugin from running any functions when a blog page is displayed to a user, minimizing the plugin’s server resource usage.

If you’re concerned about the performance of your admin panel you can then scroll up in the file (currently line 70, but this may change) to find and remove the following code (or something similar if something has changed since writing this post):

//--------------you may remove these three lines (comment them out) if you are using hard-coded PDF links in your theme. This will make your admin panels run slightly more efficiently.--------------
 add_action('save_post', 'kalinsPDF_save_postdata');
 add_meta_box( 'kalinsPDF_sectionid', __( "PDF Creation Station", 'kalinsPDF_textdomain' ), 'kalinsPDF_inner_custom_box', 'post', 'side' );
 add_meta_box( 'kalinsPDF_sectionid', __( "PDF Creation Station", 'kalinsPDF_textdomain' ), 'kalinsPDF_inner_custom_box', 'page', 'side' );

If the code comments give you information that differs from what you read here, trust the code comments as they are more likely to be up-to-date.

4 thoughts on “PDF Creation Station – hard code PDF link into theme”

  1. What about custom post types? I saw you mention on the plugin’s support page on WordPress.org that you did add CPT support. Does that change that link at all? (I haven’t dug through the code yet.)

    1. Yeah, I’m pretty sure I remember checking that this works for custom post types. Just use the code you’d use on a regular post. Let me know if you run into any troubles.

  2. Hi, the two examples above of code for inserting the link on a post and a page template are identical. Shouldn’t the second one have: singlepost=pg_ instead of po_ ?

Leave a Reply

Your email address will not be published. Required fields are marked *