admin管理员组文章数量:1303054
I disabled all plugins on my wordpress and keept only my very simple theme active. On functions.php I let running the following code:
add_action( 'wp_enqueue_scripts', function() {
// Omitted some code - Here I just call a custom function to print logs
wp_debug_backtrace_summary(); // Just indicating that I call this function on log
// The script exists and is correctly added to the frontend
wp_enqueue_script( 'main-script', get_stylesheet_directory_uri() . '/assets/js/scripts.js', array('jquery'), '1.0', true );
}, 101 );
On the log, I get that this function run twice - you can see above two payloads from wp_debug_backtrace_summary()
:
[2020-02-10 20:58:37 - ...\wp-content\themes\storms-theme\services\storms-assets.php at "backtrace" on line 42]
== Funcao de teste ===================================
Array
(
[0] => StormsFramework\Helper::backtrace
[1] => {closure}
[2] => WP_Hook->apply_filters
[3] => WP_Hook->do_action
[4] => do_action('wp_enqueue_scripts')
[5] => wp_enqueue_scripts
[6] => WP_Hook->apply_filters
[7] => WP_Hook->do_action
[8] => do_action('wp_head')
[9] => wp_head
[10] => require('/themes/storms-theme/template-parts/head.php')
[11] => load_template
[12] => locate_template
[13] => get_template_part
[14] => require_once('/themes/storms-theme/header.php')
[15] => load_template
[16] => locate_template
[17] => get_header
[18] => include('/themes/storms-theme/page.php')
[19] => require_once('wp-includes/template-loader.php')
[20] => require('wp-blog-header.php')
)
=====================================================================
[2020-02-10 20:58:37 - ...\wp-content\themes\storms-theme\services\storms-assets.php at "backtrace" on line 42]
== Funcao de teste ===================================
Array
(
[0] => StormsFramework\Helper::backtrace
[1] => {closure}
[2] => WP_Hook->apply_filters
[3] => WP_Hook->do_action
[4] => do_action('wp_enqueue_scripts')
[5] => wp_enqueue_scripts
[6] => WP_Hook->apply_filters
[7] => WP_Hook->do_action
[8] => do_action('wp_head')
[9] => wp_head
[10] => require('/themes/storms-theme/template-parts/head.php')
[11] => load_template
[12] => locate_template
[13] => get_template_part
[14] => require_once('/themes/storms-theme/header.php')
[15] => load_template
[16] => locate_template
[17] => get_header
[18] => include('/themes/storms-theme/index.php')
[19] => require_once('wp-includes/template-loader.php')
[20] => require('wp-blog-header.php')
)
I notice the item 18 on both backtrace are different:
[18] => include('/themes/storms-theme/page.php')
[18] => include('/themes/storms-theme/index.php')
If I comment the code line that enqueue the script wp_enqueue_script( 'main-script', ... )
The payload I get says my function run only once!
[2020-02-10 21:13:21 - ...\wp-content\themes\storms-theme\services\storms-assets.php at "backtrace" on line 42]
== Funcao de teste ===================================
Array
(
[0] => StormsFramework\Helper::backtrace
[1] => {closure}
[2] => WP_Hook->apply_filters
[3] => WP_Hook->do_action
[4] => do_action('wp_enqueue_scripts')
[5] => wp_enqueue_scripts
[6] => WP_Hook->apply_filters
[7] => WP_Hook->do_action
[8] => do_action('wp_head')
[9] => wp_head
[10] => require('/themes/storms-theme/template-parts/head.php')
[11] => load_template
[12] => locate_template
[13] => get_template_part
[14] => require_once('/themes/storms-theme/header.php')
[15] => load_template
[16] => locate_template
[17] => get_header
[18] => include('/themes/storms-theme/page.php')
[19] => require_once('wp-includes/template-loader.php')
[20] => require('wp-blog-header.php')
)
I have no idea what is wrong here. Why is running twice?
本文标签: wp enqueue scriptAction hooked on wpenqueuescripts running twice
版权声明:本文标题:wp enqueue script - Action hooked on wp_enqueue_scripts running twice 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741728709a2394744.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论