Skip to content Skip to sidebar Skip to footer

Jquery Conflict! Shows White Screen On Post Edit Page For Wordpress

I have a made a small jQuery script to import values from other file and insert this values in WordPress POST page as Custom Meta Tags. When I Create A New Post the form is shown b

Solution 1:

First off this seems like a bad thing to be doing editing the wordpress core. But if you want to do this, don't include jQuery again. And don't use the $ sign, see this example:

jQuery(".SomeClass").click(function(){
    console.log("Some Text");
});

//Therefore you could do something like this<scripttype="text/javascript">jQuery(document).ready(function() {
       jQuery('.button-test-class').click(function() {
             //Do what you want here, for this we'll write some text to the consoleconsole.log("Some Text");
        });
  });
</script><inputtype="button"class="button-test-class button"value="Button Test">

Solution 2:

How to add scripts The WordPress Way:

add_action( 'wp_enqueue_scripts', 'pjso_my_scripts' );
functionpjso_my_scripts() {
    $handle = 'script_name';
    $src = '/path/to/script.js';
    $deps = array( 
        'jquery',
    );
    // add any other dependencies to the array, using their $handle$ver = 'x.x';  // if you leave this NULL, // then it'll use WordPress's version number$in_footer = true; // if you want it to load in the page footer
    wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );
}

To do it only on the Edit Post screen in the backend, you can use the admin_enqueue_scripts hook combined with get_current_screen():

add_action( 'admin_enqueue_scripts', 'pjso_my_scripts' );
functionpjso_my_scripts() {
    $screen = get_current_screen();
    if( 'post' != $screen->base || 'edit' != $screen->parent_base ) {
        return; // bail out if we're not on an Edit Post screen
    }
    $handle = 'script_name';
    $src = '/path/to/script.js';
    $deps = array( 
        'jquery',
    );
    // add any other dependencies to the array, using their $handle$ver = 'x.x';  // if you leave this NULL, // then it'll use WordPress's version number$in_footer = true; // if you want it to load in the page footer
    wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );
}

That should work, though I haven't tested it.

This code can go in your theme's functions.php file, or you could write a custom plugin so that it will persist across any future theme changes.

References

Post a Comment for "Jquery Conflict! Shows White Screen On Post Edit Page For Wordpress"