Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

<?php
function add_match_attendance_scripts() {

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

            jQuery(function () {
$("#seatt_start").datepicker({dateFormat: "dd-mm-yy"});
$("#seatt_expire").datepicker({
    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);
     }
   });
});

</script>';

                echo $output;
        } 
            add_action('admin_head','add_match_attendance_scripts');
?>

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

add_action('admin_head','add_report_custom_scripts');

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 .= '});
    </script>';

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
add comment

1 Answer

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 )
        return;
    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
add comment

Your Answer

 
discard

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.