Where to insert Google Maps API code in functions.php

Your API key is URL encoded as a GET variable like so: wp_enqueue_script( ‘google_js’, ‘https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&key=yourKeyHere’, ”, ” ); I don’t urlencode the handle. The function/class does that. So if you’re having problems getting the script to load, don’t urlencode the handle.

JavaScript is not enqueuing

The name prototype is already used by WordPress. In wp-includes/script-loader.php, you’ll find this line: $scripts->add( ‘prototype’, ‘https://ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js’, array(), ‘1.7.1’); Your file will be correctly enqueued if you change the script handle: wp_enqueue_script( ‘yourprefix_prototype’, plugins_url( ‘/prototype.js’, __FILE__ ), array(‘jquery’), ‘1.0’, true ); You’ll find the list of included JS scripts and their handles on the wp_enqueue_script() … Read more

How to import the css in the plugin admin area?

Just hook your callback into admin_print_styles, i.e.: add_action( ‘admin_print_styles’, ‘mytheme_add_init’ ); Alternately, you could add an is_admin() conditional wrapper inside your callback, and hook into wp_enqueue_scripts: function mytheme_add_init() { if ( is_admin() ) { $file_dir=get_bloginfo(‘template_directory’); wp_enqueue_style(“functions”, $file_dir.”/scripts/custom.css”, false, “1.0”, “all”); wp_enqueue_script(“rm_script”, $file_dir.”/scripts/custom.js”, false, “1.0”); } } add_action( ‘wp_enqueue_scripts’, ‘mytheme_add_init’ ); But the absolute best approach … Read more

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

How register library to use jquery correct

You should use the built-in version of jQuery for compatibility reasons. All you need to do is to enqueue it: function theme_scripts() { wp_enqueue_script(‘jquery’); } add_action(‘wp_enqueue_scripts’, ‘theme_scripts’); Or just add it as a dependency for your script: function theme_scripts() { wp_enqueue_script( ‘my-script’, <PATH>, array(‘jquery’), … ); } add_action(‘wp_enqueue_scripts’, ‘theme_scripts’); But then… you have to remember, … Read more

How to execute Javascript on a WordPress page?

<?php function enqueue_javascript_for_certain_page() { $page_id = 100; // change this to fit your needs if ( is_page( $page_id ) ) { // check the page you are on wp_enqueue_script( ‘my_script_name’, // script handle get_template_directory_uri() . ‘/js/my-js-file.js’, // script URI array( // your script is dependent on following: ‘jquery’, ‘jquery-ui’ ), NULL, // script version (NULL … Read more