WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to call the following script on a plugin admin page:

function add_match_attendance_scripts() {

$output = '<script type="text/javascript">

            jQuery(function () {
$("#seatt_start").datepicker({dateFormat: "dd-mm-yy"});
    dateFormat: "dd-mm-yy",
    firstDay: 1,
    onSelect: function (prev_date) {
        prev = prev_date.split("-");
        var date = new Date(prev[2], prev[1] - 1, prev[0]);
        var d = date.getDate();
        var m = date.getMonth();
        var y = date.getFullYear();
        var new_date = new Date(y, m, d - 7);
        $("#seatt_start").removeAttr("disabled").datepicker("setDate", new_date);


                echo $output;

I already have enqueued jquery-ui-datepicker for all admin pages and it works correctly on all admin pages using a similar function:


function add_report_custom_scripts() {
global $report_custom_meta_fields, $post;

$output = '<script type="text/javascript">
            jQuery(function() {';

foreach ($report_custom_meta_fields as $field) { // loop through the fields looking for certain types
    // date
    if($field['type'] == 'date')
        $output .= 'jQuery(".datepicker").datepicker({ dateFormat: "dd-mm-yy", firstDay: 1 });';


$output .= '});

echo $output;

but apparently this script runs on my plugin page and not the one I wanted. So how can I specify which script goes where seeing as they are both admin pages?

share|improve this question
up vote 2 down vote accepted

You can review the explanation here to include any script here

function my_enqueue($hook) {
    if( 'edit.php' != $hook )
    wp_enqueue_script( 'my_custom_script', plugins_url('/myscript.js', __FILE__) );
add_action( 'admin_enqueue_scripts', 'my_enqueue' );

The above code will add the script in all your admin pages.

In order to identify the page you may follow this:

if (isset($_GET['page']) && $_GET['page'] == 'wp-accordion') {
    // do all of your add_action() hooks here

Here "page" is the get variable which you defined in your created plugin while adding menus.

I hope you find my answer useful.

share|improve this answer
It took me a while but it seems to be working now. Thank you. – mantis Jul 2 '13 at 12:18
Oh, i am glad that it worked, great! and thank you for accepting. Would you mind to give an upvote? – Md Toufiqul Islam Jul 3 '13 at 11:16
Sure there you go. – mantis Jul 3 '13 at 11:44
:) liked it awesome! – Md Toufiqul Islam Jul 3 '13 at 11:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.