WordPress.org

Ready to get started?Download WordPress

Forums

FancyBox
This plugin enqueues script incorrectly (1 post)

  1. Gabriel Luethje
    Member
    Posted 1 year ago #

    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/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

  • RSS feed for this topic
  • Started 1 year ago by Gabriel Luethje
  • This topic is not resolved
  • WordPress version: 3.1.2

Tags

No tags yet.