Please consider not printing scripts
-
A very dirty but effective fix is for WP v.4.5.0+
--- /home/classte/backup/easy-fancybox-class.php 2016-07-06 19:49:15.301943718 +0200 +++ easy-fancybox-class.php 2016-07-08 14:15:55.503965124 +0200 @@ -1,4 +1,23 @@ <?php + +/** + * Introduce this script to WordPress as a localized script. + * + * This will be placed BEFORE the $footer_handle script in the footer. + * FIXME Will it be printed in the footer with a header script's handle? + * + * @FIXRES + */ +function fixres_easy_fancybox( $buffer ) { + global $wp_scripts; + $name = 'easy-fancybox-inline-script'; + $footer_handle = 'jquery-fancybox'; + $buffer = trim( preg_replace( '#<script[^>]*>(.*)</script>#is', '$1', $buffer ) ); + $fix_res_banner = "/* RELOCATED {$name} */\n"; + wp_add_inline_script( $footer_handle, $fix_res_banner . $buffer ); + return "<!-- FIXRES {$name} optimized -->\n"; +} + /** * Easy FancyBox Class */ @@ -17,8 +36,7 @@ public static function main_script() { - echo ' -<!-- Easy FancyBox ' . EASY_FANCYBOX_VERSION . ' using FancyBox ' . FANCYBOX_VERSION . ' - RavanH (http://status301.net/wordpress-plugins/easy-fancybox/) -->'; +// echo '<!-- Easy FancyBox ' . EASY_FANCYBOX_VERSION . ' using FancyBox ' . FANCYBOX_VERSION . ' - RavanH (http://status301.net/wordpress-plugins/easy-fancybox/) -->'; // check for any enabled sections //if(!empty(self::$options['Global']['options']['Enable']['options'])) @@ -31,13 +49,12 @@ } // and abort when none are active if (!self::$add_scripts) { - echo ' -<!-- Nothing enabled under Settings > Media > FancyBox. --> - - '; +// echo '<!-- Nothing enabled under Settings > Media > FancyBox. --> '; return; } + // @FIXRES + ob_start( 'fixres_easy_fancybox' ); // begin output FancyBox settings echo ' <script type="text/javascript"> @@ -234,6 +251,8 @@ /* ]]> */ </script> '; + ob_end_flush(); + // @FIXRES - END // customized styles $styles = '';
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘Please consider not printing scripts’ is closed to new replies.