doulao1966 2016-08-13 16:23
浏览 87

wp_enqueue_scripts不起作用

I created my own javascript file and now I want to integrate into my module. I'm trying to do as told in this site https://developer.wordpress.org/reference/functions/wp_enqueue_script/ But it does not work, I don't understand why

P.S: I am in the main file of my module (exampe.php)

class exemple
{
    public function __construct()
    {
        register_activation_hook(__FILE__, array('exemple_bd', 'install'));

        register_uninstall_hook(__FILE__, array('exemple_bd', 'uninstall'));

        include_once plugin_dir_path( __FILE__ ).'settings.php';
        new Settings();

        add_action('admin_menu', array($this, 'add_admin_menu'));
        add_action('admin_init', array($this, 'load_JS'));         
    }

    public function add_admin_menu()
    {
        add_menu_page('monTitre', 'Monplugin', 'manage_options','xxx', array($this, 'menu_html'),'dashicons-email');
        add_submenu_page('xxx', 'NouveauTitre', 'NouveauTitre', 'manage_options', 'xxx', array($this, 'menu_html'));

    }

    public function load_JS()
    {
        wp_register_script('myfunction',plugins_url( '/js/function.js', __FILE__ ));
        wp_enqueue_script('myfunction');
    }
  • 写回答

2条回答 默认 最新

  • douliang1369 2016-08-13 17:02
    关注

    You need to register them with action hook "wp_enqueue_scripts". Use "admin_enqueue_scripts" for admin scripts.

    The function should be called using the wp_enqueue_scripts action hook if you want to call it on the front-end of the site, like in the examples above...

    https://developer.wordpress.org/reference/functions/wp_enqueue_script/#notes

    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序