My code will not execute in wordpress, even though I’ve been told the code is fine

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.

$299 Affordable Web Design WordPress

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

My code will not execute in wordpress, even though I’ve been told the code is fine

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.