How to check if the current page is 'admin panel'?


#1

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 :slight_smile:


#2

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).”


#3

I meant that ‘can we check that we’re in admin panel?’ sorry, forgot about ‘functions.php’,it was my confusion. Thanks :slight_smile:


#4
saintdo said

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 :slight_smile:

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: http://codex.wordpress.org/Function_Reference/wp_enqueue_script

EDIT: Im assuming you want to load a script to a specific admin page and not the whole admin panel?


#5
OrganicBeeMedia said
saintdo said

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 :slight_smile:

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: http://codex.wordpress.org/Function_Reference/wp_enqueue_script

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! :smiley: