Notice: wp_enqueue_script was called incorrectly. in Wordpress debug mode
wp_enqueue_script('like_post', get_template_directory_uri().'/js/post-like/post-like.js', array('jquery'), '1.0', true );
wp_localize_script('like_post', 'ajax_var', array(
'url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('ajax-nonce')
));
add_action('wp_ajax_nopriv_post-like', 'mytheme_post_like');
add_action('wp_ajax_post-like', 'mytheme_post_like');
The Code above is working and my postlike system is working fine like that, however Im getting Notice: wp_enqueue_script was called incorrectly. in wordpress debug mode but its working.
When I try to do it as a function in the right way the like buttons not working the javascript is broken and also when I try to add this only for single pages using the
if( !is_admin() && is_single() ) {
the javascript is brtoken too, the like dislike buttons not working.
Can u help me on this? How can I get this in the right way and only for the single pages?
Thanks
Solutions
Try this:
add_action( 'wp_enqueue_scripts', 'gazi_theme_enqueue_scripts' );
function gazi_theme_enqueue_styles(){
wp_enqueue_script('like_post', get_template_directory_uri().'/js/post-like/post-like.js', array('jquery'), '1.0', true );
}
wp_localize_script('like_post', 'ajax_var', array( 'url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('ajax-nonce') ));
add_action('wp_ajax_nopriv_post-like', 'mytheme_post_like');
add_action('wp_ajax_post-like', 'mytheme_post_like');
Similar questions
Notice: map_meta_cap was called incorrectly
I created an external script to import json data into a custom post type that uses wp-load.php. Everything works fine but after every update I get the message Im calling the script inside a child theme and post_type_exists returns false but works fine... Ive seen a similar notice in a core track thread but it talks about comments being the issue an...
Notice: wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder
With code above its working completely fine only problem i am getting this Notice: when debug mode is on. And i shouldn't have any notices. Notice: wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder. Is there any suggestion? I know removing prepare( would take away the problem. But i want to keep the...
Notice: register_uninstall_hook was called incorrectly
I automatically updated my wordpress installation to the latest version. Everything looked normal unit "updating database..." where it got stuck. I waited for a long while and then closed the page, since nothing was happening. Then I got a error message saying something about maintenance, which I got rid of after deleting the maintenance file. Word...
Woocommerce - internal server error: Notice: id was called incorrectly
My site has a problem. On checkout I get the Internal server error. I have read almost all the solutions provided on forums and even on this forum but none proved to solve this problem. Here is the error log below. Notice: id was called incorrectly. Order properties should not be accessed directly. Backtrace: require(‘wp-blog-header.php’), require_...
Notice: register_rest_route was called incorrectly
In my Wordpress site, this issue appears when adding or editing posts. Note: I didn't make any WP update or any plugin update on the site. Any idea to fix this issue? Thank you.
string(2) "id" Notice: id was called incorrectly. Product properties should not be accessed directly. Backtrace:
string(2) "id" Notice: id was called incorrectly. Product properties should not be accessed directly. Backtrace: require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), include('/plugins/woocommerce/templates/single-product.php'), wc_get_template_part, load_template, require('/plugins/woocommerce/templates/content-...