Version Information
- Plugin Name: JSM's file_get_contents() Shortcode
- Stable Version: 2.4.0
- Author: JS Morisset
- Description: A safe and reliable WordPress shortcode for PHP's file_get_contents() function.
- License: GPLv3
- Requires PHP: 7.2 or newer
- Requires WordPress: 5.4 or newer
- Tested Up To WordPress: 6.1.1
- Last Updated: 3 hours ago
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 = Wrap the content in the specified div class (default is none).
- esc_html = Escape HTML characters (default is false).
- file = Path to a local file (relative to the wp-content/ folder).
- filter = Apply the specified filter to the content (default is none).
- more = Add more link on non-singular web pages (default is true).
- pre = Wrap the content in <pre></pre> HTML tags (default is false).
- url = URL or file URI.
- utf8 = Encode HTML entities (default is true).
Note that all local file paths are relative to the wp-content/ folder - you cannot include files 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 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').
1 2 3 |
define( 'WPFGC_SHORTCODE_NAME', 'include' ); |
Shortcode Examples
1 2 3 4 5 6 |
[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_filter_name" cache="600"] |
There are tons of uses for this but for us it is an solution for SPA automated HTML backend deployments.