WordPress.org

Ready to get started?Download WordPress

Forums

jQuery Colorbox
[resolved] Deregister and consolidate scripts (5 posts)

  1. aaclayton
    Member
    Posted 2 years ago #

    Hey techotronic, first off, thanks for this awesome plugin.

    I have one request which you might be able to help me with. I would really like to fold the included jquery/js/css into my own theme files so I can minify the whole thing to eliminate unnecessary calls in my header.

    Unfortunately your colorbox plugin seems to be immune to my usual methods for deregistering a plugin script. Here's what I've been trying.

    add_action( 'wp_print_scripts', 'remove_colorbox_scripts', 100 );
    function remove_colorbox_scripts() {
        wp_deregister_script( ' jquery ' );
        wp_deregister_script( ' colorbox ' );
        wp_deregister_script( ' colorbox-wrapper ' );
    }

    I've tried some variations of this approach, but can't seem to get it to take. Any suggestions for correcting my method?

    Thanks again for the great plugin.

    http://wordpress.org/extend/plugins/jquery-colorbox/

  2. techotronic
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,
    no idea, I just use wp_enqueue_script () to register and load the scripts for the plugin.

    Why don't you use the "W3 Total Cache" plugin to minify CSS and JS?
    It works fine on all WordPress sites that I maintain...

    Cheers,
    Arne

  3. Mladen Gradev
    Member
    Posted 1 year ago #

    I am trying to do the same thing, but I can not deregister colorbox css. @aaclayton if you find a solution, please share it with me.

  4. aaclayton
    Member
    Posted 1 year ago #

    It's not a solution I'm proud of, but my initial fix was to hack the plugin core and remove the script and style registration.

    Arne, I agree that W3TC is a great utility, I use it myself. However, automatic consolidation and minification isn't a perfect substitute to having only one CSS and one JS file enqueued in the first place.

    I had forgotten about this issue, in retrospect, I think my problem was I was attempting to wp_deregister_script() when I should have been using wp_dequeue_script().

    I'm at work atm, so I can't try this now...but:

    wp_dequeue_script( 'jquery' );
    wp_dequeue_scropt( 'colorbox-wrapper' );
    wp_dequeue_script( 'colorbox' );

    should knock out the JS enqueues, while:

    wp_dequeue_style( 'colorbox-[theme]' );

    should kill off the css, you'll need to replace [theme] with the correct handle for the colorbox theme you have selected in plugin options.

    Mladen, let me know if this gives you any luck.

  5. Mladen Gradev
    Member
    Posted 1 year ago #

    Aaclayton,
    Thank you for help and fast reply. I made it :)
    This is what i did:
    1. Add this code to functions.php . I am using Colorbox theme 9.

    add_action( 'wp_print_styles', 'my_deregister_styles', 100 );
    function my_deregister_styles() {
    wp_deregister_style( 'colorbox-theme9' );
    }

    2. After that i have made some changes to jquery-colorbox-frontend.php on lines 287 and 288. I have replaced colorboxTheme with theme9 on three places.

    At this moment Colorbox CSS is deregistered and images are still opening, but they are ugly and have no functions.

    3. Then I copy theme9 CSS code from wp-content/plugins/jquery-colorbox/themes/theme9/colorbox.css to my main style.css

    Now colorbox opens the images, but there are no buttons. Still everything is working, by pressing left and right you can navigate in gallery. This is because the paths to images are messed in style.css. To fix this you need to:

    4. Copy the images from wp-content/plugins/jquery-colorbox/themes/theme9/images to your themes directory image folder. Or to change the paths in Colorboxs css part in your main style.css.

    And that`s it. Colorbox is working again and even faster. :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.