• Referencing topic by Daedalon – https://www.ads-software.com/support/topic/plugin-facebook-like-box-patch-enqueue-style-and-script-only-when-used (although his solution doesn’t solve the problem entirely.)

    The plugin enqueues and prints both CSS and JS scripts on every page – both front-end and dashboard.

    However, it seems that, these files are only required for Plugin options page in the Dashboard and no where else!

    Patch

    1. Remove admin_init and wp_enqueue_scripts hooks
      These are the culprits for the problem – Line 12 and 13.

      These are not at all required.

    2. Hook add_menu_page to enqueue the CSS and JS files
      Since the files are only required(?) for FB Like Box options page, assign add_menu_page to a variable, for example, $my_admin_page.

      Then hook off the load-{$my_admin_page} action and hook off the admin_enqueue_scripts action to enqueue the files.

      function cardoza_fb_like_options(){
      
      	$my_admin_page = add_menu_page(........);
      	add_submenu_page(........);
      	add_action('load-' . $my_admin_page, 'cardoza_load_scripts');
      }
      
      function cardoza_load_scripts() {
      	add_action('admin_enqueue_scripts', 'cfblb_enq_scripts');
      }

      Reference: https://wordpress.stackexchange.com/a/76420/31933

    And we are done.

    @vinoj Cardoza – You have not updated the plugin for 10 months. Please consider to do it now!

    https://www.ads-software.com/plugins/cardoza-facebook-like-box/

Viewing 1 replies (of 1 total)
  • Thread Starter Srihari Thalla

    (@daxserver)

    And consider loading JS script in the footer. Just that it’s better to load JS files in the footer.

    wp_enqueue_script('cfblbjs', plugins_url('/cardozafacebook.js', __FILE__), array('jquery'), false, true);

Viewing 1 replies (of 1 total)
  • The topic ‘[Patch] Enqueue style and script only when used in Dashboard’ is closed to new replies.