• Resolved audioscavenger

    (@audioscavenger)


    Your plugin is great, no doubt about it.

    Now, I have an issue that I think everyone has without noticing: the code we add in the “footer” is overridden by the scripts that are loaded after.

    It’s an order priority issue between plugins maybe, I don’t know. The code we add in the footer do appear in the footer that’s true, but at the very beginning. Your plugin place it before the wordpress scripts, jquery, and any other CDNjs scripts we may add via WP CDNjs plugin or else.

    Is this the correct way to do it? I cannot believe I’m the only one having this issue.

    IMHO It should be after all of these additional scripts, at the very end. Because the js code we add may be jquery, so it won’t work. And because the CSS we add will be overridden by the scripts loaded after. Think about Bootstrap, AnchorJS etc.

    Why is so?
    Is there any way to change this?
    Will an option to place the footer code at the very end be available in the future versions?

    thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author SilkyPress

    (@diana_burduja)

    Hi there,

    thanks for letting me know about this. You are right, it makes more sense to print the scripts at the very end.

    Please update to the 3.11 version. There the footer scripts are printed right before the </body> tag.

    Plugin Author SilkyPress

    (@diana_burduja)

    Sorry, I reverted the changes in the 3.12 version, as the hook used for printing the scripts before the </body> tag is also used in the back-end, which was breaking the back-end of other users.

    I’ll need to spend more time to look for a proper solution for this issue.

    Thread Starter audioscavenger

    (@audioscavenger)

    May i suggest this in custom-css-js.php ?

        /**
         * Add the appropriate wp actions with priority hack
         */
        function print_code_actions() {
            foreach( $this->search_tree as $_key => $_value ) {
                $priority = (int)end(explode('-',$_key));  //scav
                switch ($priority) {
                  case ($priority > 1 && $priority < 5):
                    $priority = $priority + 10;
                    break;
                  case ($priority > 4 && $priority < 10):
                    $priority = $priority * 4;
                    break;
                  case 10:
                    $priority = 9999;
                    break;
                }
                $action = 'wp_';
                if ( strpos( $_key, 'admin' ) !== false ) {
                    $action = 'admin_';
                }
                if ( strpos( $_key, 'login' ) !== false ) {
                    $action = 'login_';
                }
                if ( strpos( $_key, 'header' ) !== false ) {
                    $action .= 'head';
                } else {
                    $action .= 'footer';
                }
                add_action( $action, array( $this, 'print_' . $_key ), $priority );
            }
        }

    And in admin-screens.php:1120
    $tree_branch = $options['side'] . '-' .$options['language'] . '-' . $options['type'] . '-' . $options['linking'] . '-' . $options['priority']; //scav: add priority at the end

    priorities in footer:
    1-10 = code at the very beginning.
    11-19 = code at the beginning but just after the internet defense league js from jetpack.
    20-9998 = code after the wordpress scripts, cdnjs etc. Still before the wpadminbar div. what i wanted.
    9999+ = just before the /body, after wpadminbar div.

    I don’t know what use you make of priorities since I didn’t pay the premium to put my hands on the code. I supposed that was the purpose of the priority field, but reading your former answers, it’s just a priority between the custom scripts isn’t it ??

    Plugin Author SilkyPress

    (@diana_burduja)

    You can download and install the 3.14-beta2 version from here. There you’ll find the issue with the priority solved.

    If everything works alright, then I’ll get the changes in the next version, which should be published in about 10 days.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘footer code position before external scripts is overridden’ is closed to new replies.