WordPress.org

Ready to get started?Download WordPress

Forums

Slimbox
Properly enqueue scripts (2 posts)

  1. angelxube
    Member
    Posted 1 year ago #

    Hello,

    Thank you for plugin but consider update a way for enqueue scripts and styles.

    function slimbox_enqueue() {
    	wp_enqueue_script('jquery');
    
    	wp_enqueue_script('jquery.slimbox', WP_PLUGIN_URL."/slimbox/javascript/jquery.slimbox.js", array('jquery'), '2.03');
    
    	wp_enqueue_style('jquery.slimbox', WP_PLUGIN_URL."/slimbox/stylesheets/jquery.slimbox.css", false, '2.03');
    
    		add_action('wp_head', 'slimbox');
    	}
    add_action('wp_enqueue_scripts', 'slimbox_enqueue');

    I am PHP noob but i don't want violate any Notifications by wordpress.

    Thanks

    http://wordpress.org/extend/plugins/slimbox/

  2. Russell Jamieson
    Member
    Posted 2 months ago #

    Just to elaborate on this issue:

    If you have warnings switched on, then WordPress complains about scripts not being enqueued at the 'wp_enqueue_scripts' hook and this stop the slimbox from working - you just get a darkened screen when the lighbox is activated.

    The patch is to replace

    if (!is_admin()) :
    	wp_enqueue_script('jquery');
    	wp_enqueue_script('jquery.slimbox', WP_PLUGIN_URL."/slimbox/javascript/jquery.slimbox.js", array('jquery'), '2.03');
    	wp_enqueue_style('jquery.slimbox', WP_PLUGIN_URL."/slimbox/stylesheets/jquery.slimbox.css", false, '2.03');
    	add_action('wp_head', 'slimbox');
    endif;

    By

    function slimbox_enqueue_scripts() {
    	wp_enqueue_script('jquery');
    	wp_enqueue_script('jquery.slimbox', WP_PLUGIN_URL."/slimbox/javascript/jquery.slimbox.js", array('jquery'), '2.03');
    	wp_enqueue_style('jquery.slimbox', WP_PLUGIN_URL."/slimbox/stylesheets/jquery.slimbox.css", false, '2.03');
    	add_action('wp_head', 'slimbox');
    }
    
    if (!is_admin()) :
    	add_action('wp_enqueue_scripts','slimbox_enqueue_scripts');
    endif;

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags