Skip to content

Instantly share code, notes, and snippets.

@ebinnion
Created January 21, 2013 23:30
Show Gist options
  • Save ebinnion/4590551 to your computer and use it in GitHub Desktop.
Save ebinnion/4590551 to your computer and use it in GitHub Desktop.
Enqueue Script and Js in Plugin
add_action('template_redirect', 'audience_intel_add_js');
function audience_intel_add_js() {
// enqueue script
wp_enqueue_script( 'audience_intel_js',
plugins_url( 'js/script.js' , __FILE__ ),
array('jquery'), audience_intel_version, true
);
// Get current page protocol
$protocol = isset( $_SERVER["HTTPS"] ) ? 'https://' : 'http://';
// Outpit admin-ajax.php URL with same protocol as current page
$params = array(
'ajaxurl' => admin_url('admin-ajax.php', $protocol)
);
wp_localize_script( 'audience_intel_js', 'audience_intel_js', $params );
wp_register_style( 'audience-intel-style', plugins_url('css/plugin.css', __FILE__) );
wp_enqueue_style( 'audience-intel-style' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment