Making WordPress print-friendly and registering shortcodes.

While not everyone has to worry about creating printer-friendly content, at the Free Methodist Church – USA, this feature is in high demand.

There are a lot of ways to go about it, but we settled on using printfriendly, along with their fantastic WordPress plugin.

While the plugin offers a lot of customization, we ran into one small hitch. Whatever icon or link you choose, it’s inserted within the post content itself, while the natural place to insert it would be to the right of the metadata.

Printfriendly provides a great option for this too. You’re able to use the following snippet of PHP to insert it manually into templates:

<!--?php if function_exists('pf_show_link')){echo pf_show_link();} ?>

Fanstastic. Now we can just stick this wherever we want. If you want it to appear only on posts, just throw it in the single.php file.

However, we use often use custom post types on our network, and it would be a pain to have to put the code in each of their templates.

Thankfully, our Canvas theme has a built-in meta manager allowing us to modify the metadata for each post using shortcodes.

All that was left then, was to register the new shortcode:

<!--?php function printfriendly_func( $atts ){
 if (is_single() && function_exists('pf_show_link')){echo pf_show_link();}
}
add_shortcode( 'printfriendly', 'printfriendly_func' ); ?>

Now, we have a handy print-formatting tool available across our network, with minimal setup time.

19. January 2012
Leave a comment

Leave a Reply

Required fields are marked *

*