WPThumbs
Themes Plugins By purpose By industry Best-of lists Fix it guides
Free Plugin by JS Morisset v2.7.1

JSM file_get_contents() Shortcode

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

JSM file_get_contents() Shortcode

The facts

Rating
5★ from 1
Active installs
300+
Price
Free
Last updated
13 Aug 2026
Added
Jun 2014
Requires WP
6.0
Tested up to
WP 7.1
Requires PHP
7.4.33
Downloads
13,949

Our analysis

AI-assisted

The JSM file_get_contents() Shortcode is a WordPress plugin that allows you to use a shortcode to safely retrieve and display content from local files or external URLs. It provides various attributes to control how the content is processed and displayed, such as caching options and HTML escaping.

This plugin is suitable for users who need to include content from files or URLs in their WordPress site without compromising security. It is particularly useful for developers who want to manage content dynamically while ensuring safe access to file paths.

Best for: This plugin suits WordPress developers and site owners needing to include dynamic content from files or URLs.

What it does well

  • Allows retrieval of content from local files and external URLs
  • Supports caching for improved performance
  • Provides multiple attributes for content formatting and security
  • Can be customised with a different shortcode name

Where it falls short

  • Limited to files within the wp-content/ folder for security reasons
  • No additional features or extensive documentation provided

Verdict

The JSM file_get_contents() Shortcode offers a straightforward solution for including file content in WordPress, with a focus on security and customisation. It may be beneficial for those comfortable with using shortcodes and managing file paths.

From the developer

JS Morisset's own description of JSM file_get_contents() Shortcode, lightly tidied.

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

Shortcode Attributes

  • body = Keep only the content between <body></body> HTML tags (default is true).
  • cache = Number of seconds to cache the contents (defaults is 3600 seconds).
  • class = Add a class to the content ‘div’ container (default is none).
  • code = Wrap the content in a container (default is false).
  • code_class = Add a class to the ‘code’ container (default is none).
  • code_lang = Escape HTML characters, wrap the content in a
    container, and add a language class to the ‘code’ container (default is none).
  • esc_html = Escape HTML characters (default is false).
  • esc_html_pre_code = Escape HTML characters and wrap the content in a
    container (default is false).
  • file = Path to a local file (relative to the wp-content/ folder).
  • filter = Apply the named filter to the content (default is none).
  • more = Add a more link on non-singular web pages (default is true).
  • pre = Wrap the content in a
     container (default is false).
  • pre_class = Add a class to the ‘pre’ container (default is none).
  • pre_code = Wrap the content in a
    container (default is false).
  • pre_lang = Escape HTML characters, wrap the content in a
    container, and add a language class to the ‘pre’ container (default is none).
  • pre_title = Add a title to the ‘pre’ container (default is none).
  • url = URL or file URI.
  • utf8 = Encode HTML entities (default is true).

Note that all file paths (not URLs) are relative to the wp-content/ folder. For security reasons, it is not possible to include files outside the wp-content/ folder. As an 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

&#91;wpfgc url="http://example.com/dir/file.html"&#93;

&#91;wpfgc url="http://example.com/counter/" cache="7200"&#93;

&#91;wpfgc url="file://dir/file.html"&#93;

&#91;wpfgc file="/dir/file.txt" pre="true" filter="my_custom_filter_name" cache="600"&#93;

&#91;wpfgc file="examples/example-1.php" code_lang="php"&#93;

Read the full description on the official page →

Tagged as

Alternatives

Other plugins for making sites fast.

WP-Optimize

Get caching and more with this powerful cache plugin. Cache, optimize images, clean your database and minify f...

Free 1M+ installs 4.8★ (2,606)
LiteSpeed Cache

All-in-one unbeatable acceleration &amp; PageSpeed improvement: caching, image/CSS/JS optimization...

Free 7M+ installs 4.8★ (2,764)
EWWW Image Optimizer

Comprehensive image optimization with WebP, AVIF, Lazy Load, and more. Optimize images automatically for Faste...

Free 1M+ installs 4.8★ (1,838)
Under Construction

Easy to use Under Construction Page &amp; Coming Soon Page. Enable Under Construction Mode in seconds &amp; sh...

Free 600k+ installs 4.8★ (1,285)
Smush

Smush

93

Compress and optimize images, enable lazy load, serve WebP &amp; AVIF, and speed up your site with a global im...

Free 1M+ installs 4.8★ (6,051)
Converter for Media

Speed up your website by using our WebP &amp; AVIF Converter. Optimize images and serve WebP and AVIF images i...

Free 500k+ installs 4.9★ (1,097)