您需要正确地包括脚本和样式,就像这里所做的那样https://github.com/radekzz/wordpress-react-in-theme
add_action( \'wp_enqueue_scripts\', \'enqueue_my_react_app\' );
function enqueue_my_react_app(){
foreach( glob( get_template_directory(). \'/myReactApp/build/static/js/*.js\' ) as $file ) {
// $file contains the name and extension of the file
$filename = substr($file, strrpos($file, \'/\') + 1); wp_enqueue_script( $filename, get_template_directory_uri().\'/myReactApp/build/static/js/\'.$filename);
} foreach( glob( get_template_directory(). \'/myReactApp/build/static/css/*.css\' ) as $file ) {
// $file contains the name and extension of the file
$filename = substr($file, strrpos($file, \'/\') + 1); wp_enqueue_style( $filename, get_template_directory_uri().\'/myReactApp/build/static/css/\'.$filename);
}
}