A fresh mix of code snippets and tutorials

Display external files with a shortcode

Here is a cool snippet to display an external file anywhere in your WordPress theme.

Open your theme’s functions.php file and add the following code:

function show_file_func($atts) {
	extract(shortcode_atts(array('file'=>''), $atts));
	if ($file!='') return @file_get_contents($file);
add_shortcode('show_file', 'show_file_func');

With that in place you can use this shortcode to display the specified file anywhere in your posts or pages (or theme using do_action()).

[show_file file="http://example.com/image.png"]

Learn more

Digging Into WordPressWordPress Themes In DepthWizard’s SQL Recipes for WordPress