plugins - wp_enqueue_script fails to include in footer

In my Wordpress plugin I try to include two scripts in the page footer, like so:function my_interface_enqueues() {wp_enq

In my Wordpress plugin I try to include two scripts in the page footer, like so:

function my_interface_enqueues() {
        wp_enqueue_script( 'require-js', plugin_dir_url( __FILE__ ) . 'js/libs/requirejs/require.js', array(), false, true );
        wp_enqueue_script( 'main-js', plugin_dir_url( __FILE__ ) . 'js/main.js', array(), false, true );
    }

Yet when I check the rendered page, the scripts are inside the <head>, despite the 5th parameter being set true. What could cause this?

Wordpress version is 4.7.3

In my Wordpress plugin I try to include two scripts in the page footer, like so:

function my_interface_enqueues() {
        wp_enqueue_script( 'require-js', plugin_dir_url( __FILE__ ) . 'js/libs/requirejs/require.js', array(), false, true );
        wp_enqueue_script( 'main-js', plugin_dir_url( __FILE__ ) . 'js/main.js', array(), false, true );
    }

Yet when I check the rendered page, the scripts are inside the <head>, despite the 5th parameter being set true. What could cause this?

Wordpress version is 4.7.3

Share Improve this question asked Apr 19, 2017 at 12:02 konturkontur 1622 silver badges14 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Use the approach below to enqueue your scripts using a single action hook:

/**
 * Proper way to enqueue scripts.
 * The same approach can be used to enqueue styles.
 */
function my_interface_enqueues() {
    wp_enqueue_script( 'require-js', plugin_dir_url( __FILE__ ) . 'js/libs/requirejs/require.js', array(), '1.0.0', true );
    wp_enqueue_script( 'main-js', plugin_dir_url( __FILE__ ) . 'js/main.js', array(), '1.0.0', true );

    // Here, a sample stylesheet enqueued.
    wp_enqueue_style( 'style-name', get_stylesheet_uri() );
}
add_action( 'wp_enqueue_scripts', 'my_interface_enqueues' );

That should definitely work.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744537157a4579498.html

相关推荐

  • plugins - wp_enqueue_script fails to include in footer

    In my Wordpress plugin I try to include two scripts in the page footer, like so:function my_interface_enqueues() {wp_enq

    1天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信