WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Plugin API/Action Reference/admin print scripts

Description

admin_print_scripts mainly used to echo inline javascript in admin pages header. admin_print_scripts should not be used to enqueue styles or scripts on the admin pages. Use admin_enqueue_scripts instead.

Usage

<?php add_action( 'admin_print_scripts', 'function_name' ); ?>

where "function_name" is the name of the function to be called.

Example

function admin_inline_js(){
	echo "<script type='text/javascript'>\n";
	echo 'var pluginUrl = "'.WP_PLUGIN_URL . '/my_plugin/'.'"';
	echo "\n</script>";
}
add_action( 'admin_print_scripts', 'admin_inline_js' );

result

<script type='text/javascript'>
var pluginUrl = "http://website.com/wp-content/plugins/my_plugin/"
</script>

Note

admin_print_scripts should not be used to enqueue styles or scripts on the admin pages. Use admin_enqueue_scripts instead. admin_print_scripts could be used to insert inline script in admin pages header while admin_print_footer_scripts could be used to insert inline script in admin pages footer

Source File

admin_print_scripts() is located in wp-includes/functions.wp-scripts.php

See also

External Links

Related