I am battling with a problem for months now, that my code will not execute or show the result, when I enqueue it. I have been told, that my code is fine, and that it should work. The clock is showing, so the css and html is correct, but not doing anything. Here it is:
<?php
function childtheme_parent_styles() {
wp_enqueue_style( 'parent', get_template_directory_uri().'css/style.css' );
function mytheme_files() {
wp_enqueue_style('mytheme_main_style', get_stylesheet_uri());
wp_register_script('main-js', get_stylesheet_directory_url() . '/js/main.js');
}
add_action( 'wp_enqueue_scripts', 'childtheme_parent_styles');
wp_register_script('main-js',get_stylesheet_directory_url().'/js/main.js');
}
add_action( 'wp_enqueue_scripts', 'pr_scripts_styles' );
}
function pr_scripts_styles() {
if( is_page(507) ) {
wp_enqueue_script( 'main-js');
}
The js code is in a folder named js and in a file named main.js
setInterval(() => {
d = new Date(); //object of date()
hr = d.getHours();
min = d.getMinutes();
sec = d.getSeconds();
hr_rotation = 30 * hr + min / 2; //converting current time
min_rotation = 6 * min;
sec_rotation = 6 * sec;
hour.style.transform = `rotate(${hr_rotation}deg)`;
minute.style.transform = `rotate(${min_rotation}deg)`;
second.style.transform = `rotate(${sec_rotation}deg)`;
}, 1000);
<?php
function childtheme_parent_styles() {
wp_enqueue_style( 'parent', get_template_directory_urI().'/css/style.css' );
function mytheme_files() {
wp_enqueue_style('mytheme_main_style', get_stylesheet_uri());
wp_register_script('main-js', get_stylesheet_directory_uri() . '/js/main.js');
}
add_action( 'wp_enqueue_scripts', 'childtheme_parent_styles');
wp_register_script('main-js',get_stylesheet_directory_uri(). '/js/main.js');
}
add_action( 'wp_enqueue_scripts', 'pr_scripts_styles' );
}
function pr_scripts_styles() {
if( is_page(507) ) {
wp_enqueue_script( 'main-js');
}
Will check the dev tools.
}
at the end, also where is the code? Which file is it in. If there is an error it will show in your PHP error log, have you checked? And when you say the code doesn't run, do you mean it fails? Or the page crashes? Or there's an error? Can you be more specific?edit
link underneath the tags in your question to update it, rather than posting updated code as the solution to your question. This isn't a discussion forum so people will see you responded to your own question and assume you were posting the solution{
and}
), and hooks that add themselves inside themselves so they would never run, and functions that are started but never finished