Last active
March 4, 2020 16:36
-
-
Save bnecreative/80cc88e0c5286c68a7a0aa7d3aeca561 to your computer and use it in GitHub Desktop.
Shortcode - Output custom page content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // don't copy this line... | |
/* | |
* Custom page shortcode | |
* | |
* $atts['path'] The file that should be output relative | |
* to the current theme. | |
* | |
* @usage [custom_page path="custom-page.php"] | |
* | |
* @return ob_get_clean | |
* | |
*/ | |
function my_custom_page_shortcode( $atts ) { | |
$atts = shortcode_atts( array( | |
'path' => '', | |
), $atts, 'custom_page' ); | |
// get current theme path | |
$theme_dir = trailingslashit( get_stylesheet_directory() ); | |
ob_start(); | |
if( $atts['path'] ) { | |
if( file_exists( $theme_dir.$atts['path'] ) ) { | |
include_once( $theme_dir.$atts['path'] ); | |
} else { | |
echo 'File path not found'; | |
} | |
} else { | |
echo 'Missing file path'; | |
} | |
return ob_get_clean(); | |
} | |
add_shortcode( 'custom_page', 'my_custom_page_shortcode' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment