Google Docs Shortcode is a small plugin for WordPress that allows you to use a shortcode to easily embed a Google Doc into your blog posts or pages.
Recommended: Install the Shortcake plugin to get instant Google Doc previews in the WordPress editor.
This plugin was developed for the CUNY Academic Commons. Licensed under the GPLv2 or later.
- First, you'll need to find the public URL of your Google Doc file. Follow the guide below, then move on to step 2.
- Now navigate to your WordPress dashboard and open up the post or page where you want to embed your document. On a new line, type the following shortcode and paste in the link you copied, above:
[gdoc link="THE LINK YOU COPIED" height="800"]
You can customize the shortcode by using some custom parameters mentioned below.
Follow the steps above, but change the shortcode to:
[gdoc link="THE LINK YOU COPIED" type="audio"]
Notice the type
is set to audio
.
When you embed an audio file, we will use the browser's native HTML5 audio player.
For every other file type (image, PDF, Microsoft Office, etc.), follow the steps above, but change the shortcode to:
[gdoc link="THE LINK YOU COPIED" type="other"]
Notice the type
is set to other
.
When you embed a miscellaneous file, we will use Google's preview embed viewer to display the file.
- Login to Google Drive and locate your form. Open it.
- Next, navigate to View > Live form. This should take you to the public version of the form. Copy the URL from your browser's address bar.
- Follow step 2 from the "Embedding a document, slide or sheet" section above.
- Let's start by logging in to your Google Drive. Next, find the item you want to embed.
- Now, right-click on the file and click on Share:
- You should now be on the Share with Others window. If the "Get Shareable link" is not green, click on it:
This will make your Google Drive file shareable to anyone with the link, which will allow us to embed the file in your post. - Now, copy the link from the text field highlighted below:
Note: On iOS, users are required to interact with Google via the Apps, rather than through the browser.
-
Open the Google Document and select the ellipsis in the top right corner:
-
Select Share and Export in the resulting panel:
-
Select Copy Link and the link will be copied to your clipboard:
-
That link requires /edit?usp=sharing to be manually appended to the end of the URL in order for the shortcode to display the content correctly.
Here are some other custom parameters you can use with the shortcode:
-
"width" - By default, this tries to use your theme's content width. If this doesn't exist, the width is "100%". Fill in this value to enter a custom width.
-
"height" - Enter in a custom height for your Google Doc if desired. Defaults to "300". Avoid percentages.
-
"seamless" - This parameter is only applicable to Documents. If you enter "0", this will show the Google Docs header and footer. Default value is "1", which means that no Google Docs header or footer will be shown. Note: This option only works if your document was published to the web and not link-shared.
-
"size" - This parameter is only applicable to Slides. You can enter in "small", "medium" or "large" to use the presentation preset sizes. Dimensions for these presets are: small (480x299), medium (960x559), large (1440x839). To set a custom width and height, use the "width" and "height" parameters listed above instead.
-
"type" - This parameter is only applicable to non-Google Doc types. If the file you want to embed is an audio file, set the type to
audio
. Otherwise, set the type toother
for every other file type (image, PDF, Microsoft Office, etc.) and we will attempt to embed the file using Google's preview embed viewer.
- Hamilton-Wentworth District School Board Commons - for sponsoring Shortcake and embedding non-Google Doc types.
- Scott Voth - for testing and writing a version of this documentation on the CUNY Academic Commons codex.
- Christopher Stein - for noting a bug about using older slides with the plugin.