WordPress error when replacing local jQuery by externally-hosted

The error message describes your problem quite clearly: Notice: wp_deregister_script was called incorrectly. Do not deregister the jquery script in the administration area. To target the front-end theme, use the wp_enqueue_scripts hook. You’re de-registering the script on the init hook: add_action(‘init’, ‘replace_jquery’); This hook runs for the back and front end, but the debugger isn’t … Read more

Scripts not loading through function Method in WordPress Theme

There are several fundamental problems with what you’re trying to do that prevent you reaching your goal The Problems Naming You register 2 scripts, but you name them both ‘custom’. How is WordPress supposed to know which script you meant when you later tell it to display ‘custom’? /* Register scripts. */ wp_register_script( ‘custom’, JS … Read more

Deregister multiple scripts using a function?

First, you’re attempting to deregister too late. You need to use wp_enqueue_scripts, rather than wp_print_scripts. Second, all you need to do is add a call to wp_deregister_script() for each script you need to deregister: <?php add_action( ‘wp_enqueue_scripts’, ‘my_deregister_javascript’, 100 ); function my_deregister_javascript() { if ( !is_page(array(‘order’, ‘shopping-cart’, ‘checkout’) ) ) { wp_deregister_script( ‘tcp_scripts’ ); // … Read more

Trying to get custom js files in my admin header

Ahh ok I figured it out while researching. I needed to add the $hook parameter and pass it to my function like so: function my_admin_enqueue_scripts($hook) { global $current_screen; if ( ‘post.php’ != $hook ) return; wp_register_script(‘my-scripts’, get_template_directory_uri() . ‘/js/custom/my-scripts.js’ ); wp_enqueue_script(‘my-scripts’); wp_localize_script(‘my-scripts’, ‘wp_ajax’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ))); } This gave me the results … Read more

How should I go about registering JavaScript that isn’t a file? [duplicate]

You can hook the wp_footer action to output arbitrary JavaScript. This the same action that WordPress uses to output footer enqueued scripts. Here’s an example that encapsulates the shortcode, data, and script output in a class: <?php /* Plugin Name: WPD_Example */ class WPD_Example_Plugin { public $data = array(); function __construct() { add_shortcode( ‘wpd_example’, array( … Read more

Register scripts located in child theme?

I think that none the options you has posted actually works. You are only registering the script, you need to enqeue them. Also, you should use wp_enqueue_scripts() action hook instead of init(). function register_scripts() { wp_register_script( ‘newsletter’, get_stylesheet_directory_uri() . ‘/scripts/scripts.js’, array( ‘jquery-migrate’ ), null ); wp_enqeue(‘newsletter’); } add_action( ‘wp_enqueue_scripts’, ‘register_scripts’ );