Shortcode to display external files on your posts

January 2, 2013 at 7:51 pm

When blogging, you may need to include an external file, such as text or image, into your own posts. Here is a very useful shortcode to embed and display any external files in your blog posts.

Open your functions.php file and paste the following function in it:

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' );

Once done, you can use the shortcode. It’s pretty simple:

[show_file file="http://www.test.com/test.html"]

Thanks to Vladimir Prelovac for the handy tip!

Tags: