Right now, I’m using the code ‘is_admin()’ to check but can I specific more ?
Because of ‘is_admin()’ will work for all page in ‘backend’ but I’d like to check only if in
’functions.php’(admin panel). Is it possible?
Thanks
Can you be a little more specific. I’ve got a rough idea of what you’re trying to do except for that last part. “I’d like to check only if in ‘functions.php’(admin panel).”
I meant that ‘can we check that we’re in admin panel?’ sorry, forgot about ‘functions.php’,it was my confusion. Thanks
saintdo saidRight now, I’m using the code ‘is_admin()’ to check but can I specific more ?
Because of ‘is_admin()’ will work for all page in ‘backend’ but I’d like to check only if in
‘functions.php’(admin panel). Is it possible?
Thanks
targeting the functions.php is not possible… targeting a specific page i.e theme-options etc is possible for example…
<?php add_action( 'admin_init', 'my_plugin_admin_init' ); add_action( 'admin_menu', 'my_plugin_admin_menu' ); function my_plugin_admin_init() { /* Register our script. */ wp_register_script( 'myPluginScript', plugins_url('/script.js', __FILE__) ); } function my_plugin_admin_menu() { /* Register our plugin page */ $page = add_submenu_page( 'edit.php', __( 'My Plugin', 'myPlugin' ), __( 'My Plugin', 'myPlugin' ), 9, __FILE__, 'my_plugin_manage_menu' ); /* Using registered $page handle to hook script load */ add_action('admin_print_styles-' . $page, 'my_plugin_admin_styles'); } function my_plugin_admin_styles() { /* * It will be called only on your plugin admin page, enqueue our script here */ wp_enqueue_script( 'myPluginScript' ); } function my_plugin_manage_menu() { /* Output our admin page */ } ?>
source: wp_enqueue_script() – Function | Developer.WordPress.org
EDIT: Im assuming you want to load a script to a specific admin page and not the whole admin panel?
OrganicBeeMedia saidsaintdo saidRight now, I’m using the code ‘is_admin()’ to check but can I specific more ?
Because of ‘is_admin()’ will work for all page in ‘backend’ but I’d like to check only if in
‘functions.php’(admin panel). Is it possible?
Thankstargeting the functions.php is not possible… targeting a specific page i.e theme-options etc is possible for example…
<?php add_action( 'admin_init', 'my_plugin_admin_init' ); add_action( 'admin_menu', 'my_plugin_admin_menu' ); function my_plugin_admin_init() { /* Register our script. */ wp_register_script( 'myPluginScript', plugins_url('/script.js', __FILE__) ); } function my_plugin_admin_menu() { /* Register our plugin page */ $page = add_submenu_page( 'edit.php', __( 'My Plugin', 'myPlugin' ), __( 'My Plugin', 'myPlugin' ), 9, __FILE__, 'my_plugin_manage_menu' ); /* Using registered $page handle to hook script load */ add_action('admin_print_styles-' . $page, 'my_plugin_admin_styles'); } function my_plugin_admin_styles() { /* * It will be called only on your plugin admin page, enqueue our script here */ wp_enqueue_script( 'myPluginScript' ); } function my_plugin_manage_menu() { /* Output our admin page */ } ?>source: wp_enqueue_script() – Function | Developer.WordPress.org
EDIT: Im assuming you want to load a script to a specific admin page and not the whole admin panel?
You’re totally right and it’s working great!
Thanks!