2016-05-17 93 views
0
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'); 

以上代码工作和我的类柱系统工作正常样子,但即时得到注意:wp_enqueue_script被称为不正确。在wordpress调试模式下,但它的工作。注意:wp_enqueue_script被错误地调用。在WordPress的调试模式

当我尝试以正确的方式执行此功能时,类似的按钮无法正常工作,但是当我尝试将此仅用于使用if(!is_admin() && is_single()) {的单个页面时,javascript也会生成类似的不喜欢的内容按钮不起作用。

你能帮助我吗?我怎样才能以正确的方式获得这一点,并只为单页?

感谢

回答

1

试试这个:

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');