Archives for 

wordpress shortcode api to include an external file

WordPress shortcode snippet to display external files

I needed a quick way to automatically include external page content in my WordPress Rising Stars post.

There are two tables with latest plugin standings that are automatically generated and I wanted the post to be updated automatically when they update too.

Easiest way to accomplish this is through WordPress shortcode API with a simple code that you can add into the theme functions.php file:

Here is the 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' );

This allows you to write something like this anywhere in your post:

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

The snippet above will automatically include the contents of given page into your post. Handy, isn’t it?

Related Articles: