WordPress.org

Support

Support » Plugins and Hacks » Facebook Like Box » [Plugin: Facebook Like Box] [PATCH] Enqueue style and script only when used

[Plugin: Facebook Like Box] [PATCH] Enqueue style and script only when used

  • Currently the files cardozafacebook.css and cardozafacebook.js are enqueued and loaded on every page load of the whole site, regardless of being used or not.

    Both should be enqueued only when the plugin loads a Facebook box. Otherwise the plugin slows down every page (and makes a bigger percentage of pages too heavy to be used at all on old smartphones) even though it would be used only on a few pages.

    The patch

    1. In cardoza_facebook_like_box.php locate lines 12-13:

    wp_enqueue_style('cfblbcss', plugin_dir_url(__FILE__).'/cardozafacebook.css');
    		wp_enqueue_script('cfblbjs', plugin_dir_url(__FILE__).'/cardozafacebook.js', array('jquery'));

    and replace them with

    function cfblb_enqueue_if_needed() {
    	if ( $GLOBALS['cfblb_enqueued_already'] != true ) {
    		wp_enqueue_style('cfblbcss', plugin_dir_url(__FILE__).'/cardozafacebook.css');
    		wp_enqueue_script('cfblbjs', plugin_dir_url(__FILE__).'/cardozafacebook.js', array('jquery'));
    		$GLOBALS['cfblb_enqueued_already'] = true;
    	}
    }

    2. Locate line 173

    function widget_cardoza_fb_like($args){

    and replace it with

    function widget_cardoza_fb_like($args){
    	cfblb_enqueue_if_needed();

    3. Locate line 201

    function cardoza_facebook_like_box_sc($atts){

    and replace it with

    function cardoza_facebook_like_box_sc($atts){
    	cfblb_enqueue_if_needed();

    4. Locate line 332

    if($cfpl_enable == 'yes'){

    and replace it with

    if($cfpl_enable == 'yes'){
    			cfblb_enqueue_if_needed();

    5. And finally locate line 367

    if (is_single()) {

    and replace it with

    if (is_single()) {
    		cfblb_enqueue_if_needed();

    http://wordpress.org/extend/plugins/cardoza-facebook-like-box/

Viewing 1 replies (of 1 total)
  • Also, the slashes on lines that were previously 12-13 should be removed so that they will not produce URLs with double slashes, such as “wp-content/plugins/cardoza-facebook-like-box//cardozafacebook.css?ver=3.4.2”. The proper lines 12-13 (14-15 after the above patch) are:

    wp_enqueue_style('cfblbcss', plugin_dir_url(__FILE__).'cardozafacebook.css');
    		wp_enqueue_script('cfblbjs', plugin_dir_url(__FILE__).'cardozafacebook.js', array('jquery'));
Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Facebook Like Box] [PATCH] Enqueue style and script only when used’ is closed to new replies.
Skip to toolbar