WordPress取消排队本地化脚本不起作用



我正在尝试删除插件的javascript并将其替换为我自己的JavaScript。

插件使用以下代码注册脚本:

add_action( 'wp_enqueue_scripts', 'learndash_30_template_assets' );
function learndash_30_template_assets() {
// If this function is being called then we are the active theme.
$theme_template_url = LearnDash_Theme_Register::get_active_theme_base_url();
/**
* @TODO : These assets really should be moved to the /templates directory since they are part of the theme.
*/
wp_register_style( 'learndash-front', $theme_template_url . '/assets/css/learndash' . leardash_min_asset() . '.css', array(), LEARNDASH_SCRIPT_VERSION_TOKEN );
wp_register_script( 'learndash-front', $theme_template_url . '/assets/js/learndash.js', array( 'jquery' ), LEARNDASH_SCRIPT_VERSION_TOKEN, true );
wp_register_style( 'learndash-quiz-front', $theme_template_url . '/assets/css/learndash.quiz.front' . leardash_min_asset() . '.css', array(), LEARNDASH_SCRIPT_VERSION_TOKEN );
wp_enqueue_style( 'learndash-front' );
wp_style_add_data( 'learndash-front', 'rtl', 'replace' );
wp_enqueue_script( 'learndash-front' );
wp_localize_script( 'learndash-front', 'ajaxurl', admin_url( 'admin-ajax.php' ) );
wp_localize_script(
'learndash-front',
'ldVars',
array(
'postID'      => get_the_ID(),
'videoReqMsg' => esc_html__( 'You must watch the video before accessing this content', 'learndash' ),
)
);
if ( get_post_type() == 'sfwd-quiz' ) {
wp_enqueue_style( 'learndash-quiz-front' );
wp_style_add_data( 'learndash-quiz-front', 'rtl', 'replace' );
}
$dequeue_styles = array(
'learndash_pager_css',
'learndash_template_style_css',
);
foreach ( $dequeue_styles as $style ) {
wp_dequeue_style( $style );
}
}

我想替换"学习冲刺前"脚本。我尝试了正常的wp_dequeue_script,wp_enqueue_script:

function replace_script()
{
wp_deregister_script( 'learndash-front' );
wp_dequeue_script( 'learndash-front' );
wp_register_script( 'cu-learndash-front', get_stylesheet_directory_uri() . '/learndash/ld30/assets/js/learndash.js', array( 'jquery' ), '', true );
wp_enqueue_script( 'cu-learndash-front' );
}
add_action( 'wp_print_scripts', 'replace_script', 100 );

这添加了我的自定义脚本,但默认插件脚本仍然加载,但移动到页面末尾。

我一直在寻找,实际上在这篇文章中找到了一个可行的解决方案。

我不得不使用 add_action( 'wp_footer', 'wpse_262301_wp_footer', 11 ( 取消脚本排队 (;

最新更新