• a plugin wp_enqueue_scripts function adds 2 JS scripts in my header between meta title and description …
    How can I move them directly in front of </head> or if possible into footer?

    protected function enqueue_js($slug, $file, $ver = false, $prerequisite=false, $params=false, $footer = false, $json = false)
    {
    if(is_array($params) && $json)
    {
    ?>
    <script type=”text/javascript”>
    var <?php echo str_replace(‘-‘,’_’,$this->id).’_’.$slug; ?> = <?php echo json_encode( $params ); ?>;
    </script>
    <?php
    }
    wp_enqueue_script($this->id.($slug?(‘_’.$slug):”), $file, is_array($prerequisite)?$prerequisite:array(‘jquery’), $ver ? $ver : $this->ver, $footer);

    if(is_array($params) && !$json)
    wp_localize_script($this->id.($slug?(‘_’.$slug):”), str_replace(‘-‘,’_’,$this->id).’_’.$slug, $params);
    }
    /** function/method
    * Usage: helper for hooking css scripts
    * Arg(3): slug (string), file (string), ver (string)[optional, default: ‘0.1’]
    * Return: void
    */
    protected function enqueue_css($slug, $file, $ver = false)
    {
    wp_register_style( $this->id.($slug?(‘_’.$slug):”), $file, false, $ver ? $ver : $this->ver );
    wp_enqueue_style( $this->id.($slug?(‘_’.$slug):”));
    }
    }

    $kkStarRatings_obj = new BhittaniPlugin_kkStarRatings(‘bhittani_plugin_kksr’, ‘kk Star Ratings’, ‘2.4’);

    // Setup
    register_activation_hook(__FILE__, array($kkStarRatings_obj, ‘activate’));

    // Scripts
    add_action(‘wp_enqueue_scripts’, array($kkStarRatings_obj, ‘js’));
    add_action(‘wp_enqueue_scripts’, array($kkStarRatings_obj, ‘css’));
    add_action(‘wp_head’, array($kkStarRatings_obj, ‘css_custom’));
    add_action(‘admin_init’, array($kkStarRatings_obj, ‘admin_scripts’));

    // Menu
    add_action(‘admin_menu’, array($kkStarRatings_obj, ‘menu’));

    // AJAX
    add_action(‘wp_ajax_kksr_admin_reset_ajax’, array($kkStarRatings_obj, ‘kksr_admin_reset_ajax’));
    add_action(‘wp_ajax_kksr_ajax’, array($kkStarRatings_obj, ‘kksr_ajax’));
    add_action(‘wp_ajax_nopriv_kksr_ajax’, array($kkStarRatings_obj, ‘kksr_ajax’));

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter cluster666

    (@cluster666)

    I’ll tried placing it before </head> with:

    <?php wp_enqueue_scripts(‘bhittani_plugin_kksr’); ?>

    but then I get it twice …

    wp_enqueue_scripts has a boolean paramenter that tells WordPress to load a script in the header or footer. If you are using this function in a theme it should be executed in function.php

    As you can see, the last parameter of $in_footer can be set to ‘true’ or ‘false.’

    But if these files are being loaded by a plugin then I’m not sure what you can do.

    Thread Starter cluster666

    (@cluster666)

    thanks, I’ve already tried setting boolean paramenter as “true” but nothing changed …
    manual including could be a solution if the first include by the plugin could be turned off .. hmmm

    <?php wp_enqueue_scripts(‘bhittani_plugin_kksr’); ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘how to move wp_enqueue_scripts in front of ?’ is closed to new replies.