Last active
December 12, 2016 07:44
-
-
Save derpixler/0e6208ad4f34a97b2498d83cb9fa4ec3 to your computer and use it in GitHub Desktop.
Load custom WordPress templates or assets like js, css
This file contains hidden or 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 | |
/** | |
* Load template or assets | |
* | |
* @param $tpl | |
* @param $type | |
*/ | |
function load_plugin_assets( $tpl, $type = 'php' ){ | |
$default_tpl = $tpl . '.’ . $type; | |
$template = apply_filters( | |
'custom_load_template', | |
$default_tpl | |
); | |
if ( $overridden_template = locate_template( $template ) ) { | |
$path = $overridden_template; | |
} else { | |
$path = dirname( __FILE__ ) . '/../view/' . $default_tpl; | |
} | |
if( $type === 'php' ){ | |
load_template( $path ); | |
}else if( $type === 'css' || $type === 'js' ){ | |
// enque this here | |
} | |
} | |
load_plugin_assets( ‘foo’, 'js’ );` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment