WordPress.org

Ready to get started?Download WordPress

Forums

NextGEN Gallery ColorBoxer
[resolved] Not Working Properly in the Widgets (4 posts)

  1. adminda
    Member
    Posted 1 year ago #

    I have included a NextGen Gallery Widget in the side bar. The ColorBoxer behaves normally on the pages that also have a NextGen Gallery in the page content but on the pages that do not have a NextGen gallery in the content the ColorBoxer does not work and pictures just open as a link.
    Check this page http://lewismilitaryinsignia.com/?page_id=16 that has the a gallery in the content of the page and has "Recent Additions" side bar gallery that has ColorBoxer working properly.
    Now check the "Contact page (http://lewismilitaryinsignia.com/?page_id=4) that does not have a gallery in the page content. Note that if you click on the "Recent Additions" gallery on the side bar not the picture just open as a link and not as ColorBoxer funtion.
    Any idea what could be causing this and how to fix it.

    http://wordpress.org/extend/plugins/nextgen-gallery-colorboxer/

  2. Mark Jeldi
    Member
    Plugin Author

    Posted 1 year ago #

    Hi adminda,

    Thanks for using NextGEN Gallery ColorBoxer!

    Unfortunately, it's not currently possible in WordPress to detect if a widget (or a do_shortcode call in your theme) is actually present on a page when the head section is processed on page load, and just loading the required scripts sitewide for ColorBox to function would largely defeat the purpose of the plugin.

    BUT...I've just recently come up with a solution whereby if you tell ColorBoxer in advance which extra pages you want its scripts to run on, it will then load them conditionally in the head (where they won't break), and only on those specific pages (instead of sitewide!).

    If you add the following to the top of nextgen-gallery-colorboxer-functions.php (just after the opening <?php tag), you can instruct the ColorBox scripts to load on whichever pages you want them to (before WordPress even detects your widget)...

    /**********************************************************************
    * conditionally add colorbox scripts for nextgen image widget
    **********************************************************************/
    
    function nggcb_conditional_scripts_for_image_widget() {
    
     	if (!is_admin()) {
    		if (!is_home()) {
    
    			// see scripts-and-styles.php for functions
    			add_action('wp_enqueue_scripts', 'nggcb_load_jquery', 1000);
    			add_action('wp_enqueue_scripts', 'nggcb_load_colorbox', 1000);
    			add_action('wp_print_styles', 'nggcb_colorbox_style', 1000);
    			add_action('wp_head','nggcb_colorbox_inline_js', 1000);
    
    		}
    	}
    }
    add_action('wp','nggcb_conditional_scripts_for_image_widget');

    On your site specifically, it looks as though you've got the widget loading on every page except the homepage, so I've used an "if not homepage" conditional in the code above...but you can change this to whatever you like. For a full list of WordPress conditionals, please see this Codex page.

    Hope this helps!

    Cheers,
    Mark.

  3. adminda
    Member
    Posted 1 year ago #

    Thank you Mark that did the trick. I appreciate it!

  4. daledude
    Member
    Posted 1 year ago #

    Thanks for this!

    And if like me, you want it to only show on the front page, you can alter it to this:

    /**********************************************************************
    * conditionally add colorbox scripts for nextgen image widget
    **********************************************************************/
    
    function nggcb_conditional_scripts_for_image_widget() {
    
     	if (!is_admin()) {
    		if (is_front_page()) {
    
    			// see scripts-and-styles.php for functions
    			add_action('wp_enqueue_scripts', 'nggcb_load_jquery', 1000);
    			add_action('wp_enqueue_scripts', 'nggcb_load_colorbox', 1000);
    			add_action('wp_print_styles', 'nggcb_colorbox_style', 1000);
    			add_action('wp_head','nggcb_colorbox_inline_js', 1000);
    
    		}
    	}
    }
    add_action('wp','nggcb_conditional_scripts_for_image_widget');

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic