正如我所说,这段代码有一些问题。
右括号}
没有理由额外的,
在wp_enqueue_script
最后add_action( \'wp_enqueue_scripts\', \'my_scripts_method\');
在里面my_scripts_method
函数这是您当前的代码,带有一些格式和注释,以显示有问题的代码部分。
<?php
/**
* Astra Child Theme functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package Astra Child
* @since 1.0.0
*/
/**
* Define Constants
*/
define( \'CHILD_THEME_ASTRA_CHILD_VERSION\', \'1.0.0\' );
/**
* Enqueue styles
*/
function child_enqueue_styles() {
wp_enqueue_style( \'astra-child-theme-css\', get_stylesheet_directory_uri() . \'/style.css\', array(\'astra-theme-css\'), CHILD_THEME_ASTRA_CHILD_VERSION, \'all\' );
}
add_action( \'wp_enqueue_scripts\', \'child_enqueue_styles\', 15 );
// this closing bracket is not needed
}
function my_scripts_method() {
// this functions contains , at the end, not needed
wp_enqueue_script(\'custom-script\',get_stylesheet_directory_uri() . \'/js/custom_script.js\',);
// this add_action cannot be inside its own the callback function
add_action( \'wp_enqueue_scripts\', \'my_scripts_method\');
}
这是正确的代码。
<?php
/**
* Astra Child Theme functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package Astra Child
* @since 1.0.0
*/
/**
* Define Constants
*/
define( \'CHILD_THEME_ASTRA_CHILD_VERSION\', \'1.0.0\' );
/**
* Enqueue styles
*/
function child_enqueue_styles() {
wp_enqueue_style( \'astra-child-theme-css\', get_stylesheet_directory_uri() . \'/style.css\', array(\'astra-theme-css\'), CHILD_THEME_ASTRA_CHILD_VERSION, \'all\' );
}
add_action( \'wp_enqueue_scripts\', \'child_enqueue_styles\', 15 );
function my_scripts_method() {
// this functions contains , at the end, not needed
wp_enqueue_script(\'custom-script\',get_stylesheet_directory_uri() . \'/js/custom_script.js\');
}
add_action( \'wp_enqueue_scripts\', \'my_scripts_method\');