Skip to content

Instantly share code, notes, and snippets.

@mrbobbybryant
Created February 17, 2015 19:57
Show Gist options
  • Save mrbobbybryant/ab038826d9c2470dd226 to your computer and use it in GitHub Desktop.
Save mrbobbybryant/ab038826d9c2470dd226 to your computer and use it in GitHub Desktop.
Conditionally Loading Scripts in WordPress
<?php
function dwwp_admin_enqueue_scripts() {
//These varibales allow us to target the post type and the post edit screen.
global $pagenow, $typenow;
if ( ($pagenow == 'post.php' || $pagenow == 'post-new.php') && $typenow == 'job' ) {
//Plugin Main CSS File.
wp_enqueue_style( 'dwwp-admin-css', plugins_url( 'css/admin-jobs.css', __FILE__ ) );
//Plugin Main js File.
wp_enqueue_script( 'dwwwp-job-js', plugins_url( 'js/admin-jobs.js', __FILE__ ), array( 'jquery', 'jquery-ui-datepicker' ), '20150204', true );
//Quicktags js file.
wp_enqueue_script( 'dwwp-custom-quicktags', plugins_url( 'js/dwwp-quicktags.js', __FILE__ ), array( 'quicktags' ), '20150206', true );
//Datepicker Styles
wp_enqueue_style( 'jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css' );
}
}
//This hook ensures our scripts and styles are only loaded in the admin.
add_action( 'admin_enqueue_scripts', 'dwwp_admin_enqueue_scripts' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment