New answers tagged

1

Your code seems correct, but it will load the script only in admin area beacuse you are enqueuing the script in admin_enqueue_scripts action. To load the script in frontend, use wp_enqueue_scripts action (which is not the same that wp_enqueue_script() function): function Zumper_widget_enqueue_script() { wp_enqueue_script( 'my_custom_script', ...


0

UPDATED: Use this code instead function Zumper_widget_enqueue_script() { wp_enqueue_script( 'my_custom_script', plugin_dir_url( __FILE__ ) . 'js/jquery.repeatable.js', array('jquery'), '1.0.0', false ); } add_action('admin_enqueue_scripts', 'Zumper_widget_enqueue_script'); 3rd parameter is to declare dependency and 4th one is to define version. ...


0

The WordPress plugin Wordfence(ver. 6.0.22) was causing this issue. To fix this, go to "Options" and uncheck "Hide WordPress Version".


0

I found the problem with my enqueue statements. There was a space ahead of the handle name of the wp_enqueue_scripts statements for both "tablesorterjs" and "tablesorterfunctions". Once I removed the space in front of the handle name, the scripts enqueued. wp_register_script( 'tablesorterjs', plugins_url( '/js/jquery.tablesorter.js', __FILE__ ), ...


1

Here's how localization works. The first thing you need to do is register your script with WordPress. This pretty much tells WordPress where the script is located, what version it is, any dependants ( like jquery ), and whether it will be located in the header or footer. More importantly you need to give it a unique identifier which you'll be able to ...


2

You just have your arguments lined up wrong. Change the line to wp_enqueue_script( 'ajax-products', plugins_url( '/js/ajax.js', __FILE__ ), array('jquery'), '1.2', false ); You can use plugins_url() with the second parameter of __FILE__ to get the directory of the specific pluign, and in the first argument you pass the relative location of your script. ...


0

If you're outputting the script in the footer, you can call wp_localize_script at any point after your script is enqueued but before the script is output on wp_footer priority 20. function wp_enqueue_woocommerce_style(){ wp_enqueue_script( 'chroma_js', get_template_directory_uri() . '/js/chroma.js', '', '1.1', ...


0

I'm used this code recently to get variable in header image path.Add this function to your functions.php: function img() { return get_template_directory_uri().'/assets/img/'; } and use this in your header.php like this: <img src="<?php echo img(); ?>my-image.jpg">


0

<?php // Register the script wp_register_script( 'some_handle', 'path/to/myscript.js' ); // Localize the script with new data $translation_array = array( 'some_string' => __( 'Some string to translate', 'plugin-domain' ), 'a_value' => '10' ); wp_localize_script( 'some_handle', 'object_name', $translation_array ); // Enqueued script with ...


-1

I had missed the tag of datepicker (I wrote datepicker). Sorry!!


1

I have not directly an answer to solve your issue as it (please take a look at the edit part I add), but this codesnippet (function) could maybe help you to solve the version issues for .js as well for .css files. /** * Remove query (output)string from .js / .css * Using filters */ function wpse215386_remove_script_version( $src ){ $parts = explode( ...


0

Don't you need to be using wp_enqueue_script instead of wp_register_script? What I get from the wp_enqueue_script codex page the correct way to add scripts dependant on jQuery is: <?php function my_scripts_method() { wp_enqueue_script( 'custom-script', get_stylesheet_directory_uri() . '/js/custom_script.js', array( 'jquery' ) ...


3

To extend on @gmazzap suggestion on not using globals when you can use wp_scripts(), there is a shortcut for wp_scripts() for adding conditional comments called wp_script_add_data and likewise wp_style_add_data for conditional styles. So the correct way to use conditionals as of Wordpress 4.2 is like this: /** * IE enqueue HTML5shiv with conditionals * ...


0

Here is the easy way for adding asynchronous to all custom js files in WordPress. Add in functions.php : // Async load for all style function base_async_scripts($url) { if ( strpos( $url, '#asyncload') === false ) return $url; else if ( is_admin() ) return str_replace( '#asyncload', '', $url ); else ...


0

While the accepted answer works, I thought I'd add the up to date way on how this should be done. add_action('wp_enqueue_scripts', 'wpse_134784_enqueue_html5shiv_respond_bootstrap'); /** * Enqueue Theme Scripts and Styles * * @link https://gist.github.com/bryanwillis/7fd5356a9d18d0c7815f */ function wpse_134784_enqueue_html5shiv_respond_bootstrap() { ...


0

Trix's answer didn't work out for me on WordPress 4.4.1, but I found a solution in the code of Disable Embeds WordPress plugin. Add this code (modified) in your theme's functions.php file to remove the wp-embed.min.js file from the frontend completely: function custom_disable_embeds_init() { // Remove the REST API endpoint. ...


0

I make some pretty change and I hope this help you well. Try below code: function my_custom_tooltip() { wp_enqueue_style( 'custom_tooltip_frontend_css', plugins_url('custom-image-tooltip/custom-image-tooltip.css') ); wp_enqueue_script( 'custom_tooltip_frontend_js', plugins_url('custom-image-tooltip/custom-image-tooltip.js'), array('jquery'), '', true ); ...


-1

This wp-embed.min.js file is for embedding stuff into WordPress 4.4 or newer. The following code also gets rid of the file: // do not load the file: wp-embed.min.js (used since WordPress 4.4) function on_wp_footer_action() { wp_dequeue_script( 'wp-embed' ); } add_action( 'wp_footer', 'on_wp_footer_action', 9 );



Top 50 recent answers are included