Viewing 8 replies - 1 through 8 (of 8 total)
  • Use the special tags <!– WP-Minify CSS –> and <!– WP-Minify JS –> whereever you want. Right now i notice this plugin has an ongoing bug that prevents them being put into the footer.php. It’s as if this plugin forgets to check the footer for .js files and its own tags. Anywhere else seems to work fine.

    Hey kellogg9, I’ve noticed this bug also, and it’s a bit of a pain. After digging around a bit I found this:

    Around line 71 of wp-minify.php (v1.1.8), change:
    add_action('wp_footer', array($this, 'post_content'));
    to:
    add_action('wp_footer', array($this, 'post_content'), 20);

    This makes the post_content function fire later in the wp_footer order, after WordPress has added the footer scripts rather than before. Be aware though, this works great for me on a local MAMP server, but I’m still debugging an error on a remote server. But that may be due to the remote server being really badly set up. My error log shows:

    PHP Warning: filemtime() [<a href='function.filemtime'>function.filemtime</a>]: stat failed for /home/blahblah/public_html/site/wp-content/plugins/wp-minify/cache/b05f93d5c0524ecf706ed37d91e76733.js in /home/blahblah/public_html/site/wp-content/plugins/wp-minify/wp-minify.php on line 625

    danny

    (@danielmichel)

    ive registered enqueued all my js in functions.php and it’s still not combining

    Thanks @joel_birch that solution fixes my .js in footer problem.

    Hey, @joel_birch, thanks for you research!

    I have a question, though: is it possible to avoid changing the code of the plugin directly by adding the following TWO lines (or something like them) to functions.php?

    remove_action('wp_footer', array($this, 'post_content'));
    
    add_action('wp_footer', array($this, 'post_content'), 20);
    joel_birch

    (@joel_birch)

    @jlcarneiro I haven’t been able to get anything like this working, unfortunately. The $this part of that array refers to the WP_Minify class instance, so we would need to be able to access that from the functions.php file. I notice at the bottom of wp-minify.php that it is stored as $wp-minify but I can’t seem access it from functions.php, even with the global keyword. This is what I was trying (and failing with):

    <code>
    function fix_wp_minify_footer() {
      global $wp_minify;
      if (!is_admin() && !is_feed() && !defined('XMLRPC_REQUEST')) {
        if (isset($wp_minify) && !(isset($_GET['wp-minify-off']) && $_GET['wp-minify-off'])) {
          remove_action('wp_footer', array($wp_minify, 'post_content'));
          add_action('wp_footer', array($wp_minify, 'post_content'), 20);
        }
      }
    }
    add_action('plugins_loaded', 'fix_wp_minify_footer');
    </code>

    I haven’t attempted to markup code blocks on this forum before, so I fully expect the above to look weird.

    joel_birch

    (@joel_birch)

    Not a bad first attempt. Obviously, please ignore the <code> tags around that function.

    I am loading all js files via functions.php into the footer of the website but non of them got minified.

    This was the solution: add_action(‘wp_footer’, array($this, ‘post_content’), 20);

    Thanks to joel_birch 🙂

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Plugin: WP Minify] How to change position of minified files?’ is closed to new replies.