There’s not always a plugin for WordPress, not one that has all the content you want, that special one off, maybe stuff about your files or business info. Generate text from a PowerShell script and insert it into a WordPress page using a simple shortcode.
- Called with a simple shortcode;
- The file must reside in the wp-content\includes folder.
- Copy and paste the following function at the bottom of the functions.php file of your theme.
/**
* Server-side include shortcode.
*
* Usage: [ssi file="example.html"]
*/
function ssi_include_shortcode( $atts ) {
$atts = shortcode_atts( array(
'file' => '',
'encoding' => 'UTF-8'
), $atts, 'ssi' );
$file = 'includes/' . trim( $atts['file'], '"\'' );
$file = str_replace( array( "\xe2\x80\x9c", "\xe2\x80\x9d", "\xe2\x80\x98", "\xe2\x80\x99" ),
array( '"', '"', "'", "'" ),
$file );
$path = trailingslashit( WP_CONTENT_DIR ) . ltrim( $file, '/' );
$content = @file_get_contents( $path );
// Detect encoding and convert to UTF-8
$bom = substr( $content, 0, 2 );
$encoding = 'UTF-8';
if ( $bom === "\xFF\xFE" ) {
// UTF-16 LE with BOM
$encoding = 'UTF-16LE';
$content = substr( $content, 2 ); // Strip UTF-16 LE BOM
} elseif ( $bom === "\xFE\xFF" ) {
// UTF-16 BE with BOM
$encoding = 'UTF-16BE';
$content = substr( $content, 2 );
} elseif ( substr( $content, 0, 3 ) === "\xEF\xBB\xBF" ) {
// UTF-8 with BOM
$encoding = 'UTF-8';
$content = substr( $content, 3 );
}
$content = mb_convert_encoding( $content, $atts['encoding'], $encoding );
return apply_filters( 'ssi_include_content', $content, $path );
// return $path;
}
add_shortcode( 'ssi', 'ssi_include_shortcode' );
add_shortcode( 'ssi_include', 'ssi_include_shortcode' );
