Answer the question
In order to leave comments, you need to log in
Is there a way to load JS script for plugin in HEAD on WP without editing functions?
I am writing a plugin for WP.
I register in the plugin itself the connection of the necessary scripts through:
wp_enqueue_script('jquery-ui-tabs');
wp_enqueue_script('jquery-ui-dialog');
//далее
add_action( 'wp_enqueue_scripts', 'my_scripts' );
Answer the question
In order to leave comments, you need to log in
Jquery Ui is loaded in the footer by default, to reconnect you need to override this case.
// в админке осталяем как было
if( ! is_admin() ) {
//переопределяем загрузку ядра
wp_deregister_script( 'jquery-ui-core' );
wp_enqueue_script( 'jquery-ui-core', site_url( '/wp-includes/js/jquery/ui/core.min.js' ), array('jquery') );
//переопределяем загрузку api виджетов
wp_deregister_script( 'jquery-ui-widget' );
wp_enqueue_script( 'jquery-ui-widget', site_url( '/wp-includes/js/jquery/ui/widget.min.js' ), array('jquery') );
// табы
wp_deregister_script( 'jquery-ui-tabs' );
wp_enqueue_script( 'jquery-ui-tabs', site_url( '/wp-includes/js/jquery/ui/tabs.min.js' ), array('jquery') );
//диалог
wp_deregister_script( 'jquery-ui-dialog' );
wp_enqueue_script( 'jquery-ui-dialog', site_url( '/wp-includes/js/jquery/ui/dialog.min.js' ), array('jquery') );
}
By default, scripts should be displayed in the Header https://codex.wordpress.org/Function_Reference/wp_... if you set the last parameter to true then it will be in the footer. Perhaps you have some kind of plugin, or the theme has an output in the footer.
default theme is just the point (((
function my_scripts(){
wp_enqueue_style('fitness_calc_css',plugins_url('fitness_calc/ui/jquery-ui.css'));
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui -tabs');
wp_enqueue_script('jquery-ui-dialog');
wp_enqueue_script('jquery-ui-tooltip');
wp_enqueue_script('fitness_calc',plugins_url('fitness_calc/fitness_calc.js'),array(),false, true);
}
add_action( 'wp_head', 'my_scripts' ); I
've tried other hooks too. I don't know where to dig ((
Working option. Scripts \ styles should always be included via wp_enqueue_scripts \ wp_enqueue_styles respectively.
function my_scripts() {
wp_enqueue_script(
'fitness_calc',
plugins_url('fitness_calc/fitness_calc.js'),
array(), null,
false // этот - последний - параметр указывает, в футере выводить или нет
);
}
add_action('wp_enqueue_scripts', 'my_scripts', 100);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question