-
-
Save jbutko/5886012 to your computer and use it in GitHub Desktop.
WP, function.php: Register & Enqueue scripts and styles
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 | |
// Scripting | |
// Register various scripts | |
function organizedthemes_script_register() { | |
if( !is_admin()){ | |
wp_register_script('vids', get_template_directory_uri() . '/js/fitvids.js', array('jquery'), NULL, true ); | |
wp_register_script('flex', get_template_directory_uri() . '/js/flexslider.js', array('jquery'), NULL, true ); | |
wp_register_script('nanoscroller', get_template_directory_uri() . '/js/nanoscroller.js', array('jquery'), NULL, true ); | |
wp_register_script('masonry', get_template_directory_uri() . '/js/masonry.js', array('jquery'), NULL, true ); | |
wp_register_script('superfish', get_template_directory_uri() . '/js/superfish.js', array('jquery'), NULL, true ); | |
wp_register_script('hoverintent', get_template_directory_uri() . '/js/hoverIntent.js', array('jquery'), NULL, true ); | |
wp_register_script('mediaelement', get_template_directory_uri() . '/js/mediaelement/mediaelement.js', array('jquery'), NULL, false ); | |
} | |
} | |
add_action('init', 'organizedthemes_script_register'); | |
// Load scripts on all pages | |
function organizedthemes_load_default_scripts() { | |
if( !is_admin()){ | |
wp_enqueue_script('vids'); | |
wp_enqueue_script('hoverintent'); | |
wp_enqueue_script('superfish'); | |
wp_enqueue_script('nanoscroller'); | |
wp_enqueue_script('masonry'); | |
} | |
} | |
add_action('wp_enqueue_scripts', 'organizedthemes_load_default_scripts'); | |
// Conditionally load slideshow and masonry scripts | |
function organizedthemes_conditional_script_loading() { | |
if ( is_page_template( 'page-home.php' ) || has_post_format('gallery') ) { | |
wp_enqueue_script('flex'); | |
} | |
if ( is_singular( 'podcast' ) || is_taxonomy( 'series' ) || is_taxonomy( 'speaker' ) || is_archive( 'podcast' ) ) { | |
wp_enqueue_script( 'mediaelement' ); | |
} | |
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { | |
wp_enqueue_script( 'comment-reply' ); | |
} | |
} | |
add_action('wp_enqueue_scripts', 'organizedthemes_conditional_script_loading'); | |
// add ie conditional html5 shim to header | |
function organizedthemes_add_ie () { | |
echo '<!--[if lt IE 9]><script src="'.get_template_directory_uri().'/js/html5.js"></script>'; | |
echo '<script src="'.get_template_directory_uri().'/js/respond.js"></script>'; | |
echo '<style> .shadow { behavior: url('.get_template_directory_uri().'/js/PIE.htc) }</style><![endif]-->'; | |
} | |
add_action('wp_head', 'organizedthemes_add_ie'); | |
// Add media element style | |
function organizedthemes_style_retister() { | |
if( !is_admin()){ | |
wp_register_style('mediaelementcss', get_template_directory_uri() . '/js/mediaelement/mediaelementplayer.css', '', NULL, 'screen' ); | |
} | |
} | |
add_action('init', 'organizedthemes_style_retister'); | |
// enqueue styles | |
function organizedthemes_load_mediaelement_style() { | |
if ( is_singular( 'podcast' ) || is_taxonomy( 'series' ) || is_taxonomy( 'speaker' ) || is_archive( 'podcast' ) ) { | |
wp_enqueue_style('mediaelementcss'); | |
} | |
} | |
add_action('wp_enqueue_scripts', 'organizedthemes_load_mediaelement_style'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment