【问题标题】:Put a custom js code in wordpress? [duplicate]在wordpress中放置自定义js代码? [复制]
【发布时间】:2016-05-17 12:06:44
【问题描述】:

我尝试输入这样的代码:http://codepen.io/lormski/pen/meXadK/

$(function() {
   $("#tabs").tabs({
   show: {
   effect: "blind",
   direction: "right",
   duration: 300
  }
});
   $("#accordion").accordion();

   var btn = $('#accordion li a');
   var wrapper = $('#accordion li');

    $(btn).on('click', function() {
    $(btn).removeClass('active');
    $(btn).parent().find('.addon').removeClass('fadein');

    $(this).addClass('active');
    $(this).parent().find('.addon').addClass('fadein');
  });
});

在我的 wordpress 网站中(主题 Avada)

如果有人知道怎么做;)

【问题讨论】:

  • 您需要知道如何将自定义 js 文件链接到您的主题吗?
  • 是的,请!谢谢

标签: javascript jquery wordpress


【解决方案1】:

$ WordPress 中的选择器将失败,您需要将代码启动为:

<script>
jQuery(document).ready(function($){
  //your code here using $
});
</script>

在 AVADA 中,您可以转到选项 -> 高级 -> 代码字段(跟踪等)并在那里添加代码。

编辑:

请注意,codepen 已包含 jQuery UI!

如果尚未包含 jQuery ui,您还需要在您的主题中包含它。将此添加到 AVADA 子的 functions.php 中

function my_scripts() {
        wp_enqueue_script('jquery-ui-core');
}
add_action('wp_enqueue_scripts', 'my_scripts');

希望有帮助

【讨论】:

  • 我在控制台中有这个错误: (index):218 Uncaught TypeError: jQuery(...).tabs is not a function(anonymous function) @ (index):218i @ jquery.js ?ver=1.12.3:2j.fireWith @jquery.js?ver=1.12.3:2n.extend.ready @jquery.js?ver=1.12.3:2K @jquery.js?ver=1.12.3:2
  • 我更新为包含 jquery ui。让我知道这是否有效。
猜你喜欢
  • 2016-05-07
  • 2014-04-23
  • 2018-05-20
  • 2012-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多