WordPress.org

Ready to get started?Download WordPress

Forums

WP Minify
How to change position of minified files? (9 posts)

  1. Breakfab
    Member
    Posted 1 year ago #

    Hi,

    i'm using Minify 1.2.0., i've to change the position of the minified files for some conflict with others files. I'd like to move them just after the title of the page. Cheers

    http://wordpress.org/extend/plugins/wp-minify/

  2. Kimberly
    Member
    Posted 1 year ago #

    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.

  3. joel_birch
    Member
    Posted 1 year ago #

    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

  4. danielmichel
    Member
    Posted 1 year ago #

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

  5. dcrosbie
    Member
    Posted 1 year ago #

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

  6. José Luís
    Member
    Posted 1 year ago #

    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);
  7. joel_birch
    Member
    Posted 12 months ago #

    @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.

  8. joel_birch
    Member
    Posted 12 months ago #

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

  9. endolil
    Member
    Posted 11 months ago #

    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 :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.