wordpress snippets last updated   : October 6, 2014
we now have 641 snippets

Include external file shortcode

wordpress snippet

Adding this snippet to the functions.php of your wordpress theme will let you include an external file into your post / page using a shortcode. Interesting snippet something you should be careful within but could come in handy for a number of people.

snippet :  PHPcopy
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' );
source →
snippet :  SHORTCODEcopy
[show_file file="http://www.mysite.com/somefile.html"]
source →

Did you like this post? If so please share it with your friends. Thanks!

  • http://www.facebook.com/betsyfranz Betsy Franz

    Will this work in a widget area?

    • http://wpsnipp.com Kevin Chard

      You would need to enable shortcode for widgets, eg:

      add_filter(‘widget_text’, ‘do_shortcode’);

  • Maxi

    very nice!

  • masspamak

    Its sounds good but how to include code that works ? I mean, I have a nextgen gallery stuff I would include this way, but shortcode does not works (it show nextgen shortcode and not the thumbnails) also plugins does not works (such as auto-hyperlink, even css does not works) on the remote included file’s contents.

  • Tuyen


  • http://c3mdigital.com/ Chris Olbekson

    This snipp has serious security implications. It could allow any editor or user to access and read the contents of any file on the server. You could use the WordPress built in HTTP API and use wp_remote_get instead of file_get_contents().