wordpress外部js没有加载我的主题

I am making my first wordpress theme but when i tried to load external js in my theme its not loading in my page instead of that it load in wp-admin page

functions.php

wp_enqueue_script('jquery');
wp_enqueue_script('scripts', get_template_directory_uri() . '/js/scripts.js', array('jquery'),'1.0', true );

my script.js

(function($) {

    alert("it workd!!");
})(jQuery);
wp_enqueue_script('jquery');

 wp_register_script('myscripts', get_template_directory_uri() . '/js/scripts.js', array('jquery'), '1.0.0'); // Custom scripts
 wp_enqueue_script('myscripts'); // Enqueue it!

this is working

Try this

add_action('wp_enqueue_scripts', 'your_func');

function your_func(){ wp_enqueue_script('jquery'); wp_enqueue_script('scripts', get_template_directory_uri() . '/js/scripts.js', array('jquery'),'1.0', true ); }

I'm on a phone, so the formatting sucks, but that should work.

Here is the proper way to enqueue script or js file in WordPress wp-admin page

Enqueue a custom stylesheet in the admin

To load a CSS and/or Javascript file to all admin pages. You can do this from within your plugin or from your themes function file.

/** * Register and enqueue a custom stylesheet in the WordPress admin.*/
function enqueue_custom_admin_style() {

   //===============================
   // ========= CSS file ===========
   //===============================
   // Register Style
   wp_register_style( 'custom_wp_admin_css', get_template_directory_uri() . '/admin-style.css', false, '1.0.0' );

    //Enqueue by register ID.
    wp_enqueue_style( 'custom_wp_admin_css' );
    //===============================
    // ======= End CSS file =========
    //===============================

    //===============================
    // ========= JS file ===========
    //===============================
    wp_enqueue_script( 'my_custom_script', get_template_directory_uri().'myscript.js', array(), '1.0' );
    //===============================
    // ======== End JS file =========
    //===============================
}
add_action( 'admin_enqueue_scripts', 'enqueue_custom_admin_style' );