WordPress.org

Ready to get started?Download WordPress

Forums

wp_register_script and wp_register_style not working (1 post)

  1. crod310
    Member
    Posted 1 year ago #

    0 down vote favorite

    hi so I used a great tutorial off of http://scribu.net/wordpress/optimal-script-loading.html and I am having trouble loading the scripts when a shortcode called lightbox is used here is my code. I am at the page when it is called wanted to check with someone to see if it is properly written.

    class fancy{
    static $add_script;

    static function init() {
    add_shortcode('lightbox', array(__CLASS__, 'handle_shortcode'));

    add_action('init', array(__CLASS__, 'register_script'));
    add_action('wp_footer', array(__CLASS__, 'print_script'));
    }

    static function handle_shortcode($atts) {
    self::$add_script = true;

    // actual shortcode handling here
    }

    static function register_script() {
    wp_register_script('fancybox', get_stylesheet_directory_uri('/js/jquery.mousewheel-3.0.6.pack.js', __FILE__), array('jquery'), '3.06', true);
    wp_register_script('fancybox', get_stylesheet_directory_uri('/js/jquery.fancybox.js', __FILE__), array('jquery'), '1.0', true);
    wp_register_script('fancybox', get_stylesheet_directory_uri('/js/jquery.fancybox.pack.js', __FILE__), array('jquery'), '1.0', true);
    wp_register_script('fancybox', get_stylesheet_directory_uri('/js/jquery.fancybox-buttons.js', __FILE__), array('jquery'), '1.0', true);
    wp_register_script('fancybox', get_stylesheet_directory_uri('/js/jquery.fancybox-media.js', __FILE__), array('jquery'), '1.0', true);
    wp_register_script('fancybox', get_stylesheet_directory_uri('/js/jquery.fancybox-thumbs.js', __FILE__), array('jquery'), '1.0', true);
    wp_register_style('fancybox', get_template_directory_uri('/css/jquery.fancybox.css', __FILE__), array('css'), '1.0', true);
    wp_register_style('fancybox', get_template_directory_uri('/css/jquery.fancybox-buttons.css', __FILE__), array('css'), '1.0', true);
    wp_register_style('fancybox', get_template_directory_uri('/css/jquery.fancybox-thumbs.css', __FILE__), array('css'), '1.0', true);

    }
    static function print_script() {
    if ( ! self::$add_script )
    return;

    wp_print_scripts('fancybox');
    }
    }

    fancy::init();

Topic Closed

This topic has been closed to new replies.

About this Topic