0

This plugin has an unique way of registering styles and scripts so I have no idea on how to stop it from loading on all my pages. After a quick search to see where wp_enqueue_style&script is I came up with this.

Line 263:           wp_enqueue_style($h);
Line 277:             wp_enqueue_style('thickbox');

Line 143:             add_action('wp_enqueue_scripts', array( &$this, 'frontend_print_scripts'), 20 );
Line 203:           wp_enqueue_script($h);
Line 227:               wp_enqueue_script('media-upload');
Line 228:               wp_enqueue_script('thickbox');

Then I looked for register_and_enqueue_js and came up with this.

        function register_and_enqueue_js($file, $d = array(), $v = false, $f = false) {
      if ($v === false) {
        $v = $this->plugin_version;
      }

      $js_src_url = $file;
      if ( ! WPPBUtils::str_contains($file, '://') ) {
        $js_src_url = $this->plugin_url . 'js/' . $file;
      }            
      $h = str_replace('.', '-', pathinfo( $file, PATHINFO_FILENAME ) );

      wp_register_script(
              $handle = $h,
              $src = $js_src_url,
              $deps = $d,
              $ver = $v,
              $in_footer = $f);

      wp_enqueue_script($h);
    }        

    function admin_print_script_if_exists($js_file) {

      if (file_exists($this->plugin_dir . 'js/' . $js_file)) {

        $this->register_and_enqueue_js($js_file, array('jquery'));

      }
    }       

For css I found this

 function register_and_enqueue_css($file, $d = false, $v = false) {
      if ($v === false) {
        $v = $this->plugin_version;
      }

      $css_src_url = $file;
      if ( ! WPPBUtils::str_contains($file, '://') ) {
        $css_src_url = $this->plugin_url . 'css/' . $file;
      }

      $h = str_replace('.', '-', pathinfo( $file, PATHINFO_FILENAME ) );

      wp_register_style(
              $handle = $h,
              $src = $css_src_url,
              $deps = $d,
              $ver = $v);

      wp_enqueue_style($h);
    }     

This is not how all plugins enqueue and register css and js so I have no clue on how to do this.

1

If it is called by shortcode, then the shortcodes are fired before the page loads (which is why you never echo in a shortcode) - you could cut out the existing call to the enqueue, and add it to the shortcode function at the top.

If not, then as RRikesh suggests, you could wrap the relevant code in a if(is_page(1)) {...] statement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.