Skip to content

Instantly share code, notes, and snippets.

@pietromalerba
Forked from gabrieleromanato/MyJS.php
Last active August 29, 2015 14:07
Show Gist options
  • Save pietromalerba/72600cbe888fb2de1cc3 to your computer and use it in GitHub Desktop.
Save pietromalerba/72600cbe888fb2de1cc3 to your computer and use it in GitHub Desktop.
<?php
class MyJS {
public function __construct() {
add_action( 'wp_enqueue_scripts', array( &$this, 'addScripts' ) );
}
public function addScripts() {
// jQuery
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', get_template_directory_uri() . '/js/jquery.js', array(), '2.2', true );
wp_enqueue_script( 'jquery' );
if( is_single() ) { // singolo post?
global $post; // oggetto globale $post
if( has_tag( 'galleria', $post ) ) { // il post ha il tag 'galleria' ?
wp_register_script( 'fancybox', get_template_directory_uri() . '/js/plugins/fancybox/jquery.fancybox.js', array( 'jquery' ), '2.0', true );
wp_enqueue_script( 'fancybox' );
wp_register_style( 'fancybox', get_template_directory_uri() . '/js/plugins/fancybox/jquery.fancybox.css' );
wp_enqueue_style( 'fancybox' );
}
}
// script principale
wp_register_script( 'blog', get_template_directory_uri() . '/js/blog.js', array( 'jquery' ), '1.0', true );
wp_enqueue_script( 'blog' );
}
}
$myjs = new MyJS();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment