Support » Plugin: FancyBox » This plugin enqueues script incorrectly

  • With debug on, I get the following notice:

    Notice: wp_enqueue_script was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or init hooks. Please see Debugging in WordPress for more information. (This message was added in version 3.3.) in /Users/hal/Documents/ArtFiles/web/Locality/coppercity/wp-includes/functions.php on line 2944

    This is coming from the code starting on line 32 of fancybox.php:

    if (!is_admin()) {
    	wp_enqueue_script('jquery');
    	wp_enqueue_script('jquery.fancybox', WP_PLUGIN_URL.'/fancy-box/jquery.fancybox.js', array('jquery'), '1.2.6');
    	wp_enqueue_script('jquery.easing', WP_PLUGIN_URL.'/fancy-box/jquery.easing.js', array('jquery'), '1.3');
    	wp_enqueue_style('jquery.fancybox', WP_PLUGIN_URL.'/fancy-box/jquery.fancybox.css', false, '1.2.6');
    	add_action('wp_head', 'fancybox');
    }

    I believe this should be wrapped in a function, like so:

    function fancybox_scripts(){
    	if (!is_admin()) {
    		wp_enqueue_script('jquery');
    		wp_enqueue_script('jquery.fancybox', WP_PLUGIN_URL.'/fancy-box/jquery.fancybox.js', array('jquery'), '1.2.6');
    		wp_enqueue_script('jquery.easing', WP_PLUGIN_URL.'/fancy-box/jquery.easing.js', array('jquery'), '1.3');
    		wp_enqueue_style('jquery.fancybox', WP_PLUGIN_URL.'/fancy-box/jquery.fancybox.css', false, '1.2.6');
    		add_action('wp_head', 'fancybox');
    	}
    }
    add_action('wp_enqueue_scripts', 'fancybox_scripts');

    This got rid of the notice for me, and the plugin worked fine.

    http://wordpress.org/extend/plugins/fancy-box/

  • The topic ‘This plugin enqueues script incorrectly’ is closed to new replies.