WordPress Code Snippets

A fresh mix of code snippets and tutorials

Display external files with a shortcode

43

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"]

Source

Learn more

WordPress Themes In Depth


Show Support

Like our new Facebook Page to show support!