dongpang9573 2015-12-29 16:42 采纳率: 0%
浏览 42
已采纳

在wordpress中包含javascript

I want to include my own javascript code in the front page of a wordpress site. I have located it and have tried many ways online to add javascript code to it but either the console says it failed to load the resource or that the method I called is not defined when I try to use it in an "onload" attribute. I have looked for many articles online but they seem to be talking about how to use it in a specific post. I want this code for the front page only.

This is how I have included the javascript most recently in the header file:

<?php echo '<script type="text/javascript"';
echo 'src="virtue-child/aboutUs.js"></script>'; ?>
  • 写回答

1条回答 默认 最新

  • dongmi6102 2015-12-30 11:27
    关注

    You can create custom script file in js folder of your theme and call in your theme function.php

    Ex: your script file name ->customjquery.js

    function custom_scripts() {
    
        wp_enqueue_script( 'customjquery', get_template_directory_uri() . '/js/customjquery.js', array(), '0001', true );
    
    }
    add_action( 'wp_head', 'custom_scripts' );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探