Skip to content

Instantly share code, notes, and snippets.

@scarstens
Created June 19, 2014 18:55
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 scarstens/a5142c51652516a9a244 to your computer and use it in GitHub Desktop.
Save scarstens/a5142c51652516a9a244 to your computer and use it in GitHub Desktop.
Per page CSS and JS loader for wordpress that loads CSS and JS using the URL slug. Loads if it exists, doesn't load if it doesn't exist. Its like get_template_part actions for CSS and JS files! Keywords: this, page, stylesheet, js, javascript, wordpress
//load styles and scripts for this page
add_action( 'wp_enqueue_scripts', 'this_page_stylesheet' );
add_action( 'wp_enqueue_scripts', 'this_page_js' );
function this_page_stylesheet() {
$ss_filename = str_replace('php', 'css', basename(__FILE__));
wp_enqueue_style( 'page-style', get_stylesheet_directory_uri().'/appearance/'.$ss_filename);
}
function this_page_js() {
$ss_filename = str_replace('php', 'js', basename(__FILE__));
wp_enqueue_script('page-js', get_stylesheet_directory_uri().'/js/'.$ss_filename);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment