Guest User

Untitled

a guest
Oct 22nd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. // SHORTCODE - Include File
  2. // http://www.amberpanther.com/knowledge-base/using-the-wordpress-shortcode-api-to-include-an-external-file-in-the-post-content/
  3.  
  4. function include_file($atts) {
  5. //check the input and override the default filepath NULL
  6. //if filepath was specified
  7. extract(shortcode_atts(array('filepath' => 'NULL'), $atts));
  8. //check if the filepath was specified and if the file exists
  9. if ($filepath!='NULL' && file_exists(CHILD_SS_DIR.$filepath)){
  10. //turno on output buffering to capture script output
  11. ob_start();
  12. //include the specified file
  13. include(CHILD_SS_DIR.$filepath);
  14. //assign the file output to $content variable and clean buffer
  15. $content = ob_get_clean();
  16. //return the $content
  17. //return is important for the output to appear at the correct position
  18. //in the content
  19. return $content;
  20. }
  21. }
  22. //register the Shortcode handler
  23. add_shortcode('include', 'include_file');
Add Comment
Please, Sign In to add comment