JSM's file_get_contents() Shortcode


A safe and reliable WordPress shortcode for PHP’s file_get_contents() function.

Shortcode Attributes

  • url = URL or file URI.
  • file = Path to a local file (relative to the wp-content/ folder).
  • cache = Number of seconds to cache the content in the transient cache (defaults is 3600 seconds).
  • pre = Wrap the content in <pre></pre> HTML tags (default is false).
  • class = Wrap the content in the specified div class (default is none).
  • filter = Apply the specified filter to the content (default is none).
  • more = Add more link on non-singular web pages (default is true).
  • body = Keep only the content between <body></body> HTML tags (default is true).

Note that all local file paths are relative to the wp-content/ folder — you cannot include files from outside the wp-content/ folder. For example, the shortcode attributes url="file://dir/file.html" and file="/dir/file.html" are both read as wordpress/wp-contents/dir/file.html. The .. folder name is also stripped from file paths to prevent backing out of the wp-content/ folder.

Shortcode Name

The WPFGC_SHORTCODE_NAME constant can be defined in your wp-config.php file to add an additional custom shortcode name (the default shortcode names are ‘wp-file-get-contents’ and ‘wpfgc’).

define( 'WPFGC_SHORTCODE_NAME', 'include' );

Shortcode Examples

[wpfgc url="http://example.com/dir/file.html"]
[wpfgc url="http://example.com/counter/" cache="7200"]
[wpfgc url="file://dir/file.html"]
[wpfgc file="/dir/file.txt" pre="true" filter="my_custom_filters" cache="600"]


Automated Install

  1. Go to the wp-admin/ section of your website.
  2. Select the Plugins menu item.
  3. Select the Add New sub-menu item.
  4. In the Search box, enter the plugin name.
  5. Click the Search Plugins button.
  6. Click the Install Now link for the plugin.
  7. Click the Activate Plugin link.

Semi-Automated Install

  1. Download the plugin ZIP file.
  2. Go to the wp-admin/ section of your website.
  3. Select the Plugins menu item.
  4. Select the Add New sub-menu item.
  5. Click on Upload link (just under the Install Plugins page title).
  6. Click the Browse… button.
  7. Navigate your local folders / directories and choose the ZIP file you downloaded previously.
  8. Click on the Install Now button.
  9. Click the Activate Plugin link.


12 de Abril, 2017
There are tons of uses for this but for us it is an solution for SPA automated HTML backend deployments.
Ler 1 avaliação

Contribuidores e programadores

“JSM's file_get_contents() Shortcode” é software de código aberto. As seguintes pessoas contribuíram para este plugin:


Registo de alterações

Version Numbering

Version components: {major}.{minor}.{bugfix}[-{stage}.{level}]

  • {major} = Major structural code changes / re-writes or incompatible API changes.
  • {minor} = New functionality was added or improved in a backwards-compatible manner.
  • {bugfix} = Backwards-compatible bug fixes or small improvements.
  • {stage}.{level} = Pre-production release: dev < a (alpha) < b (beta) < rc (release candidate).


Changelog / Release Notes

Version 2.2.0 (2020/10/07)

Maintenance release.

  • New Features
    • None.
  • Improvements
    • None.
  • Bugfixes
    • None.
  • Developer Notes
    • None.
  • Requires At Least
    • PHP v7.0.
    • WordPress v4.5.