_wp_scripts_maybe_doing_it_wrong()
Helper function to output a _doing_it_wrong message when applicable.
Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.
No Hooks.
Return
null
. Nothing (null).
Usage
_wp_scripts_maybe_doing_it_wrong( $function_name, $handle );
- $function_name(string) (required)
- Function name.
- $handle(string)
- Name of the script or stylesheet that was registered or enqueued too early.
Default: ''
Changelog
Since 4.2.0 | Introduced. |
Since 5.5.0 | Added the $handle parameter. |
_wp_scripts_maybe_doing_it_wrong() wp scripts maybe doing it wrong code WP 6.5.2
function _wp_scripts_maybe_doing_it_wrong( $function_name, $handle = '' ) { if ( did_action( 'init' ) || did_action( 'wp_enqueue_scripts' ) || did_action( 'admin_enqueue_scripts' ) || did_action( 'login_enqueue_scripts' ) ) { return; } $message = sprintf( /* translators: 1: wp_enqueue_scripts, 2: admin_enqueue_scripts, 3: login_enqueue_scripts */ __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ); if ( $handle ) { $message .= ' ' . sprintf( /* translators: %s: Name of the script or stylesheet. */ __( 'This notice was triggered by the %s handle.' ), '<code>' . $handle . '</code>' ); } _doing_it_wrong( $function_name, $message, '3.3.0' ); }