programing

WordPress "wp_register_style이 잘못 호출되었습니다?"

madecode 2023. 3. 14. 22:04
반응형

WordPress "wp_register_style이 잘못 호출되었습니다?"

나는 답을 찾기 위해 구글을 샅샅이 뒤졌지만, 실제 해결책으로는 괜찮은 답을 찾을 수 없었다.그래서 먼저 제 문제를 설명하겠습니다.

WordPress의 최신 버전에서 만든 커스텀 테마를 사용하고 있습니다.

나는 내 스타일과 스크립트를 헤더에 하드코드하지 않고 적절한 일을 하고 싶었다.php 파일은 WordPress 함수를 사용하여 큐잉합니다.

디버깅을 유효하게 했을 때에 표시되는 통지는 다음과 같습니다.

Notice: wp_register_style was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. Please see Debugging in WordPress for more information. (This message was added in version 3.3.) in C:\xampp\htdocs\my-project\wp-includes\functions.php on line 3560

Notice: wp_register_style was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. Please see Debugging in WordPress for more information. (This message was added in version 3.3.) in C:\xampp\htdocs\my-project\wp-includes\functions.php on line 3560

Notice: wp_register_style was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. Please see Debugging in WordPress for more information. (This message was added in version 3.3.) in C:\xampp\htdocs\my-project\wp-includes\functions.php on line 3560

Notice: wp_register_script was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. Please see Debugging in WordPress for more information. (This message was added in version 3.3.) in C:\xampp\htdocs\my-project\wp-includes\functions.php on line 3560

Notice: wp_register_script was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. Please see Debugging in WordPress for more information. (This message was added in version 3.3.) in C:\xampp\htdocs\my-project\wp-includes\functions.php on line 3560

Notice: wp_enqueue_style was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. Please see Debugging in WordPress for more information. (This message was added in version 3.3.) in C:\xampp\htdocs\my-project\wp-includes\functions.php on line 3560

Notice: wp_enqueue_style was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. Please see Debugging in WordPress for more information. (This message was added in version 3.3.) in C:\xampp\htdocs\my-project\wp-includes\functions.php on line 3560

Notice: wp_enqueue_style was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. Please see Debugging in WordPress for more information. (This message was added in version 3.3.) in C:\xampp\htdocs\my-project-new\wp-includes\functions.php on line 3560

Notice: wp_enqueue_script was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. Please see Debugging in WordPress for more information. (This message was added in version 3.3.) in C:\xampp\htdocs\my-project\wp-includes\functions.php on line 3560

Notice: wp_enqueue_script was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. Please see Debugging in WordPress for more information. (This message was added in version 3.3.) in C:\xampp\htdocs\my-project\wp-includes\functions.php on line 3560

여기 내 관련 부분이 있다.functions.php파일:

/**
 * Register global styles & scripts.
 */
wp_register_style('my-fonts', '//fonts.googleapis.com/css?family=Lato:300,400,700,900');
wp_register_style('fontawesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css');
wp_register_style('my-styles', get_template_directory_uri() . '/assets/css/main.css');

wp_register_script('bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js', array( 'jquery' ));
wp_register_script('scripts', get_template_directory_uri() . '/assets/js/scripts.js', array( 'jquery' ));


/**
 * Enqueue global styles & scripts.
 */

wp_enqueue_style('my-styles');
wp_enqueue_style('my-fonts');
wp_enqueue_style('fontawesome');

wp_enqueue_script('bootstrap');
wp_enqueue_script('scripts');

WordPress의 '를 로드하려면 어떤 식으로든 지정해야 할 디버깅 알림으로 추측됩니다.wp_enqueue_scripts,admin_enqueue_scripts, 또는login_enqueue_scripts후크

내가 뭘 잘못했는지 알아냈어!관심 있는 사람을 위해 제가 한 일은 다음과 같습니다.

이것을 변경했습니다.

/**
 * Register global styles & scripts.
 */
wp_register_style('my-fonts', '//fonts.googleapis.com/css?family=Lato:300,400,700,900');
wp_register_style('fontawesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css');
wp_register_style('my-styles', get_template_directory_uri() . '/assets/css/main.css');

wp_register_script('bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js', array( 'jquery' ));
wp_register_script('scripts', get_template_directory_uri() . '/assets/js/scripts.js', array( 'jquery' ));


/**
 * Enqueue global styles & scripts.
 */

wp_enqueue_style('my-styles');
wp_enqueue_style('my-fonts');
wp_enqueue_style('fontawesome');

wp_enqueue_script('bootstrap');
wp_enqueue_script('scripts');

이를 위해:

function my_scripts() {
/**
 * Register global styles & scripts.
 */
wp_register_style('my-fonts', '//fonts.googleapis.com/css?family=Lato:300,400,700,900');
wp_register_style('fontawesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css');
wp_register_style('my-styles', get_template_directory_uri() . '/assets/css/main.css');

wp_register_script('bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js', array( 'jquery' ));
wp_register_script('scripts', get_template_directory_uri() . '/assets/js/scripts.js', array( 'jquery' ));


/**
 * Enqueue global styles & scripts.
 */

wp_enqueue_style('my-styles');
wp_enqueue_style('my-fonts');
wp_enqueue_style('fontawesome');

wp_enqueue_script('bootstrap');
wp_enqueue_script('scripts');
}

그리고 다음과 같이 덧붙였습니다.

add_action( 'wp_enqueue_scripts', 'my_scripts' );

"WC Fields Factory" 플러그인을 비활성화할 수 있도록 수정되었습니다.

언급URL : https://stackoverflow.com/questions/31649063/wordpress-wp-register-style-was-called-incorrectly

반응형