在自定义帖子类型存档页面中执行脚本时遇到麻烦

I have a custom post type archive page where I'd like to execute a specific script for the page. The script is loaded in the page with this function (in function.php):

function cpt_archive_enqueue_script() {
 if (is_post_type_archive('cpt-slug')) {
  wp_enqueue_script( 'cpt-archive-script', get_stylesheet_directory_uri() . '/js/cpt-archive-script.js', array( 'jquery' ), '1.0.0', true );
  };
}

add_action ('wp_enqueue_scripts', 'cpt_archive_enqueue_script'); 

As I can see with page inspector, the page loads the script but the loaded script is not executed ( the same script work f.e. if loaded in a category page).

Have anyone a suggestion to fix this? Thanks!

If can help here is the loaded script (it is a really simple script that opens the article content if the title is clicked).

jQuery(document).ready(function($) {

 $('article.post').each(function() {
   var $dropdown = $(this);

   $("div.entry-title", $dropdown).click(function(e) {
     e.preventDefault();
     $div = $("div.entry-content", $dropdown);
     $div.toggle();
     $("div.entry-content").not($div).hide();
     return false;
   });

});

 $('html').click(function(){
   $("div.entry-content").hide();
 });

});
查看全部
doushi3189
doushi3189
2017/09/06 09:46
  • wordpress
  • php
  • jquery
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复