Add jquery


#1

Hi! =)
I wont add two js file - change background image
try add to function 2 line
wp_enqueue_script( ‘sydney-color’, get_template_directory_uri() . ‘/js/jquery.color.js’, array(‘jquery’),’’, true );

    wp_enqueue_script( 'sydney-random', get_template_directory_uri() . '/js/jquery.random.js', array('jquery'),'', true );

But not worked.
How add correct please ??/ =)


#2

Dear Elena,

Thank you for getting in touch.

I suppose you are trying to enqueue script in functions.php file of child theme. If so, I’m afraid that won’t work. That function looks for the file which is stored in the parent theme directory. The correct one should be like the following.

wp_enqueue_script( 'sydney-color', get_stylesheet_directory_uri() . '/js/jquery.color.js', array('jquery'),'', true );
wp_enqueue_script( 'sydney-random', get_stylesheet_directory_uri() . '/js/jquery.random.js', array('jquery'),'', true );

I hope this reply helps.

Warmest regards,
Kharis


#3

Ok. I need add js file to sydney js folder? sydney/js ?


#4

i add to themes/sydney/js this correct?


#5

Also i have this code/
HOW ADD THIS CODE CORRECT? I greate js file and put it to js sydney folder.
And change script type - (function($){
<script type=“text/javascript”>
$(document).ready(function() {
spectrum();
function spectrum(){
var hue = ‘rgb(’ + (Math.floor(Math.random() * 256)) + ‘,’ + (Math.floor(Math.random() * 256)) + ‘,’ + (Math.floor(Math.random() * 256)) + ‘)’;
$(’#welcome’).animate( { backgroundColor: hue }, 1000);
spectrum();
}
});
</script>

After change i have this code
(function($){
$(document).ready(function() {

		spectrum();
		
		function spectrum(){
			var hue = 'rgb(' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ')';
			$('body').animate( { backgroundColor: hue }, 1000);
			spectrum(); 
	   	}
		
	});	
})(jQuery);

THIS CORRECT?


#6

Dear Alena,

> Ok. I need add js file to sydney js folder? sydney/js ?

Yes. But I thought you should take it at your own risk as you’re trying to modify the Sydney theme’s core file; all changes you have made will be lost once you update the theme in the future.

For the best practice, I’d strongly recommend you to do it in the child theme mode. You should start from here.

Warmest regards,
Kharis


#7

About lost no problem. I add js but js not worked.

(function($){
$(document).ready(function() {

spectrum();

function spectrum(){
var hue = ‘rgb(‘ + (Math.floor(Math.random() * 256)) + ‘,’ + (Math.floor(Math.random() * 256)) + ‘,’ + (Math.floor(Math.random() * 256)) + ‘)’;
$(‘body’).animate( { backgroundColor: hue }, 1000);
spectrum();
}

});
})(jQuery);

THIS CORRECT?


#8

Dear Alena,

I’m afraid we can’t provide you an assistance at this point. I know it is a bit frustrating but it’s beyond the theme support service. For general question about jQuery, I’d recommend you to post it here.

Thank you for your understanding.

Warmest regards,
Kharis