Take the tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Im developing a Form with a (jQuery) onClick button so I can import results from other documents straight into WP Custom Fields.

To do this I MUST include this script to my Form:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>

If I don't include this script then my Form wont work :(

And if I include this script then I can ADD NEW POST and use my Form + Button but then the EDIT POST page wont show up and I only see a WHITE SCREEN.

Finally I figured out if I insert this CODE to LINE 59 in admin-header.php:

<?php if ( is_admin() && $parent_file == 'edit.php') { ?>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<?php } ?>

Then everything will work 100% as I want :D

I thought WP already was using/including this script by default but this is NOT true as I can see. At least not for WP-Backend (Post page).

The problem is: I dont want to edit WP CORE files, so my question is how can I get the same result using functions.php instead of editing admin-header.php?

Just to show you how admin-header looks like from LINE 50 to LINE 73:

<title><?php echo $admin_title; ?></title>
<?php

wp_enqueue_style( 'colors' );
wp_enqueue_style( 'ie' );
wp_enqueue_script('utils');

$admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix);
?>

<?php if ( is_admin() && $parent_file == 'edit.php') { ?>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<?php } ?>

<script type="text/javascript">
addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>',
    pagenow = '<?php echo $current_screen->id; ?>',
    typenow = '<?php echo $current_screen->post_type; ?>',
    adminpage = '<?php echo $admin_body_class; ?>',
    thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>',
    decimalPoint = '<?php echo addslashes( $wp_locale->number_format['decimal_point'] ); ?>',
    isRtl = <?php echo (int) is_rtl(); ?>;
</script>

As you can se my CODE is on LINE 11,12 and 13 to make it work.

share|improve this question
add comment

2 Answers

You can try something like this in your theme functions.php

function admin_add_script() { wp_enqueue_script('jquery_script', 'http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js', array(), null); }

add_action('admin_head-edit.php', 'admin_add_script');

share|improve this answer
 
I tried your code, but this did not help me :( No results.. I have updated my question so you can see my Admin-Header.php –  Cyborg Nov 9 at 0:52
 
Ideally jquery library should be loaded on to wordpress back-end. To test it you can run some jquery line ( like jQuery(window).width() ) on the developer console ( Chrome/Firefox ) on a new / edit post page. If it doesn't throw an error, jQuery is already loaded. For the white screen on the edit post page you see, their might be some other issue, you can activate debug ( update this line define('WP_DEBUG', false); to define('WP_DEBUG', true); ) inside wp-config.php file in your root wordpress folder and see what error it throws on the edit posts screen. Hope we can find out the actual issue. –  sagar Nov 9 at 5:14
add comment

Try adding this to your functions.php:

<?php
function add_jquery_data() {

    global $parent_file;

    if ( isset( $_GET['action'] ) && $_GET['action'] == 'edit' && isset( $_GET['post'] ) && $parent_file == 'edit.php') {
        echo "<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>";
    }
}

add_filter('admin_head', 'add_jquery_data');
?>

I hope this helps.

share|improve this answer
 
This didn't work. In this function you must close PHP before entering script like: ?> <script src="http://ajax...jquery.min.js"></script> <?php I tried this and deleted my lines from admin-header.php but now my Form Dont Work :( –  Cyborg Nov 9 at 0:40
 
Sorry, my bad. Try echoing the script tag - echo "<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>‌​"; –  roofdog Nov 9 at 0:59
 
Hmm.. this didnt help either.. the same results. I guess its same if you echo or just close the PHP tag. When you echo HTML then should use ' ' instead of " " –  Cyborg Nov 9 at 1:13
 
Maybe the WP Codex will help admin_enqueue_scripts? –  roofdog Nov 9 at 1:23
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.