Skip to content

Instantly share code, notes, and snippets.

@derpixler
Last active December 12, 2016 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derpixler/0e6208ad4f34a97b2498d83cb9fa4ec3 to your computer and use it in GitHub Desktop.
Save derpixler/0e6208ad4f34a97b2498d83cb9fa4ec3 to your computer and use it in GitHub Desktop.
Load custom WordPress templates or assets like js, css
<?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