Title: Please consider not printing scripts
Last modified: September 1, 2016

---

# Please consider not printing scripts

 *  Resolved [Viktor Szépe](https://wordpress.org/support/users/szepeviktor/)
 * (@szepeviktor)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/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 = '';
       ```
   
 * [https://wordpress.org/plugins/easy-fancybox/](https://wordpress.org/plugins/easy-fancybox/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * (@ravanh)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/please-consider-not-printing-scripts/#post-7555789)
 * Why would you call that dirty? 😉 — Thanks for the code and thoughts. I’ll certainly
   consider wp_add_inline_script() for the next version!
 *  Thread Starter [Viktor Szépe](https://wordpress.org/support/users/szepeviktor/)
 * (@szepeviktor)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/please-consider-not-printing-scripts/#post-7555894)
 * You shouldn’t put strings in a variable by ob_start + echo + ob_end_flush.
 * Simply add all those strings to an array `$script[] = "var a = 0";`
    then feed
   them to wp_add_inline_script by `implode( "\n", $script );`
 * Be aware that wp_add_inline_script() is available from WP 4.5.0 only.
 * All the best to you!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Please consider not printing scripts’ is closed to new replies.

 * ![](https://ps.w.org/easy-fancybox/assets/icon-256x256.png?rev=3188201)
 * [Firelight Lightbox](https://wordpress.org/plugins/easy-fancybox/)
 * [Support Threads](https://wordpress.org/support/plugin/easy-fancybox/)
 * [Active Topics](https://wordpress.org/support/plugin/easy-fancybox/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/easy-fancybox/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/easy-fancybox/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Viktor Szépe](https://wordpress.org/support/users/szepeviktor/)
 * Last activity: [9 years, 10 months ago](https://wordpress.org/support/topic/please-consider-not-printing-scripts/#post-7555894)
 * Status: resolved