If you’re managing a WordPress-based blog or website, the Google Document Viewer is a handy way to display a PDF, spreadsheet, Word document, etc. without requiring the viewer to download it and open it with their own software. The inconvenient part is that the GDV requires passing the URL of a document to be shown, and said URL must be URL-encoded. Since it’s a pain to URL-encode URLs by hand, and since encoded URLs are hard to read, I wrote this very simple “Google DocView Link” plugin for WordPress to provide an easy way to generate URL-encoded URLs. Two shortcodes are provided: gdocview_link and gdocview_url.
1. [gdocview_link] is passed a URL and an optional text label, and returns a full clickable link.
As with [gdocview_url] the URL may be a full URL or a local URL starting with a slash.
If no label is passed, the default label “View Online” is used.
[gdocview_link url=”http://example.com/my-document.pdf” label=”View with the Google Viewer”]
2. [gdocview_url] is passed a URL and returns it URL-encoded.
This shortcode is slightly more complicated to use, but also more flexible, since you can use it to create non-text links. You could use an image as the clickable object, for example.
The URL argument may be a full URL (starting with http) or a local URL starting with a slash. If a local URL is passed, the URL of your WordPress site is automatically inserted at the beginning.
This shortcode requires you to create your own HTML <a> tag but allows the complete
flexibility to do so however you want. Example:
<a href=’[gdocview_url url=”http://example.com/my-document.pdf”]’ target=”_blank”>Click here!</a>
Note that you need to enclose the bracketed shortcode call in single quotes, not double, because if both the shortcode call and the URL within it are enclosed in the same type of quotes your browser will be confused.