First of all, you are NOT enqueuing the script.. Try this code, working in my test install.
function load_my_scripts() {
// Create the localizations array
$localize = array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
);
// Register The Script First
wp_register_script('custom-js', get_stylesheet_directory_uri() . '/js/custom.js', array('jquery'));
wp_enqueue_script('twentyfifteen-custom-js', get_template_directory_uri() . '/js/custom.js', array(), '20141010', true);
// Register the localization
wp_localize_script( 'custom-js', 'MyAjax', $localize );
// Enqueue the script
wp_enqueue_script( 'custom-js' );
}
add_action('wp_enqueue_scripts', 'load_my_scripts');
Related Posts:
- Is it possible to use wp_localize_script to create global JS variables without a specific script handle?
- enqueue and localize script in footer
- How to enqueue the script without hardcoded in the theme files?
- Localizing script to pass a value to a javascript function
- Calling wp_localize_script in a different function
- How to get, in WP page’s script, a wp enqueued script (in Functions.php)?
- Proper use of wp_localize_script?
- wp enqueue inline script due to dependancies
- How to load css in the footer [duplicate]
- How to properly dequeue scripts and styles in child theme?
- How can I enqueue protocol relative external (//ajax.googleapis.com/…) scripts?
- Can’t enqueue scripts in the footer?
- How can I remove the site URL from enqueued scripts and styles?
- Protocol neutral URLS with wp_enqueue_script (SSL issues)?
- Is it safe/recommended to use wp_enqueue_script function outside the functions.php file?
- wp_enqueue script my_javascript_file in the footer
- How to load JQuery easing script in wordpress?
- wp_localize_script with boolean and init
- Hook for writing text string after footer scripts
- Why does this line of code make photo albums appear?
- Issue with using Underscore in WordPress
- Track down where script is being enqueued from
- $wp_styles->registered not giving ALL the styles?
- Benefits to enqueuing site scripts/stylesheets?
- Adding Custom Javascript to Skeleton Child Theme
- Remove specific CSS and JS from the head
- Enqueue scripts to a specific header-.php?
- Which are the MediaElement.js scripts to enqueue
- Best way to enqueue extremely popular scripts like bootstrap and font awesome
- How to remove some external js files from source?
- The wp_enqueue_scripts hook doesn’t work at all, not from plugin, not from the template, not for frontend, not for admin pages!
- wp_enqueue_script with dependencies doesn’t work
- Help with enqueing scripts in footer after init action
- Adding custom fonts (local) to WordPress?
- wp_enqueue_script order – external vs inline js
- What are the advantages of using wp_enqueue_script()
- Modernizr check first, then move on to wp_register_script()/wp_enqueue_script
- Deregister scripts on unnecessary pages using remove_action
- Prioritizing wp enqueue scripts error
- wp_enqueue and Dependencies
- Why are files enqueued with wp_enqueue_style and wp_enqueue_script 404 Not Found?
- Utilizing WordPress’ Admin UI for plugin settings: getting accordion style
- wp_enqueue_script Doesn’t Work?
- Getting wp_footer() to work without wp_head()
- wp localizing script not works
- Script Localization doesn’t work
- Move scripts to footer, but exclude one script?
- Is there a way to list all the JavaScript scripts that are actually loaded by WordPress? Do we care?
- Is It Possible to add JS AFTER the Enqueue within the same Function?
- How to enqueue JavaScript file that depends on CSS stylesheet
- wp_editor() youtube link does not load video
- Enqueue scripts all over but not in single.php
- Enqueue customizer scripts that are bundled by webpack?
- Adding multiple wp_register_scripts for templates in WordPres?
- How do I get jQuery to Load before Bootstrap?
- Deregister multiple scripts using a function?
- How can I integrate Fancybox 3 in WordPress properly
- Where to insert Google Maps API code in functions.php
- wp_enqueue_script was called incorrectly Issue when active plugins of WordPress Admin Bar Improved
- wp_enqueue_scripts does not work
- How to add conditionals for IE browsers between certain versions?
- call my script only after loading UI library?
- Loading Scripts For Specific Template
- Modular CSS and JS in Child Themes
- All of my Scripts and Enques are getting file not found
- If a Script has been enqueued but not registered can I still removed it?
- include jquery plugin file not working
- why wp_enqueue_scripts() not working?
- How to use wp_register_script / wp_enqueue_script for multiple queries
- Getting a variable inside foreach from PHP to JS after localization
- link to JS library using wp_enqueue_scripts not working
- scripts not loading
- FullCalendar in WordPress is not working
- Proper enqueue for child theme functions.php
- Wp_deregister_script() doesn’t work
- enqueue_scripts() in child theme doesn’t work
- How do you load js and style resources from CDN with local fallback using wp_enqueue_scripts?
- Issues with wp_enqueue_script and jquery-ui
- wp_localize_script & wp_enqueue_script not working in front end
- Dynamic wp_enqueue_scripts?
- wordpress enqueue script not working
- Why do I have to specify all parameters for wp_enqueue_script to load my jquery in the footer? [closed]
- wp_enqueue_script calling jQuery at different times for different browsers?
- Get localize of a loaded javascript
- Get with jQuery the value of an ACF field
- wp_enqueue_script error with `ID`, `post_title`, `post_name` of none object
- WordPress – enqueue js issue – page broken, no error
- Enqueue script with version number not working
- Set a parent script presence status true so that child scripts load in wordpress
- correct path for enqueue script in WordPress
- map enqueue in backend
- Most optimal way of starting fresh, without using other theme or dropping old files?
- Bootstrap sticky menu in WordPress
- wp_localize_script not create variable in head section
- Bootstrap css not getting applied to the custom WordPress Dashboard Widget
- WooCommerce not enqueuing its scripts [closed]
- See Scripts used by Page
- Dequeue/deregister scripts for everybody but the administrator
- comment-reply.js is not loading
- How can I specifically enqueue scripts for edit orders pages only