manipulate a plugins shortcode

you could

remove_shortcode( 'nggallery' );

and then add it again:

function put_script_after_nggallery_shortcode( $atts ){
 global $nggShortcodes;
 $nggShortcodes->show_gallery($atts); //or otherwise duplicate the callback function
 wp_enqueue_script('special-ngg-sciprt', 'url-to-script', null, null, true);

}
add_shortcode( 'nggallery', 'put_script_after_nggallery_shortcode' );

i’m not sure my show_gallery will work, but seems logical

what script do you need to add? why not just wp_enqueue_script on its own? there isn’t any reason that the script code has to be inline.

EDIT #1

Since $nggShortcodes is apparently not a global variable, we can try using object notation… or you could just copy the contents of NextGen’s gallery shortcode callback if this doesn’t work. Also, I added a class check to ensure that this won’t break your site if NextGen is ever deactivated.

function put_script_after_nggallery_shortcode( $atts ){
   if( ! class_exists('NextGEN_Shortcodes')) return;
   NextGEN_Shortcodes->show_gallery($atts); //or paste in the callback function
 ?>

  <script type="text/javascript">
   jQuery(document).ready(function($) {
     alert('bacon');
   });

   </script>

 <?php
}
add_shortcode( 'nggallery', 'put_script_after_nggallery_shortcode' );

Leave a Comment