0
I am trying to add jquery in the theme, all css and js I put in Function are added in the code normally, but jquery that is in the directory of my theme is not being added. The file exists in the same folder as the /js/bootstrap.min.js
function enqueue_jquery() {
// retira o jquery padrão do wordpress, ok retirou
wp_deregister_script('jquery');
// Não esta adicionando este jquery, que é o que preciso, no código
wp_enqueue_script(
'jquery',
get_template_directory_uri() . '/js/jquery.js',
array(), // don't make jquery dependent on jquery...!
'1.11.1',
true
);
}
add_action('wp_enqueue_scripts', 'enqueue_jquery');
function enqueue_styles_scripts() {
//OK adicionou normal
wp_enqueue_style(
'style-theme',
get_stylesheet_uri(),
array('bootstrap-css')
);
//OK adicionou normal
wp_enqueue_style(
'bootstrap-css',
get_template_directory_uri() . '/css/bootstrap.min.css'
);
//OK adicionou normal
wp_enqueue_style(
'stylish-portfolio',
get_template_directory_uri() . '/css/othercss.css'
);
//OK adicionou normal
wp_enqueue_style(
'font-awesome',
get_stylesheet_directory_uri() . '/css/font-awesome.css'
);
//Adicionou normal, mas como depende do jquery não esta funcionando
wp_enqueue_script(
'bootstrap-js',
get_template_directory_uri() . '/js/bootstrap.min.js',null
);
}
add_action('wp_enqueue_scripts', 'enqueue_styles_scripts');
//ok adicionou normal
function wpse_ie_conditional_scripts() { ?>
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<?php
}
add_action( 'wp_head', 'wpse_ie_conditional_scripts' );
?>
On the console only appears the error that bootstrap.min.js depends on jquery to work.
I appreciate help
Thanks for the reply, I had already managed to solve with the following code directly, without using Function
wp_deregister_script('jquery');
 wp_register_script('jquery', get_template_directory_uri() . '/js/jquery.js', false, '1.11.1');
 wp_enqueue_script('jquery');
. Your explanation gave me a basis of understanding, would tell me what the effect of registering jquery outside or inside a Function?– Gislef
When you speak outside, it would put the code you quoted above, without being within a function in the
functions.php
or straight to the template?– Hamurabi Araujo
this is not within a function, and in the file Function.php
– Gislef
What happens is this: when you use one
function
allied to theadd_action()
oradd_filter()
, like up there, we’re saying the functionenqueue_jquery
is executed with the hookwp_enqueue_scripts
, for example. It is common to see directly in the code, called direct configuration of the theme itself. But to be honest, I don’t know at what point (and the positive or negative consequences) the lines would happen without the use of the hook. Guess the added code would run in the actioninit
of the theme.– Hamurabi Araujo
It makes sense, thanks for the contribution. I posted one more question Here, If you can help me again thank you
– Gislef