引导程序在我的自定义插件中不起作用

发布于 2025-02-05 13:36:08 字数 492 浏览 2 评论 0原文

// register jquery and style on initialization
add_action('init', 'register_script');
function register_script() {
    wp_register_style( 'bootstrap', plugins_url('/bootstrap/css/bootstrap.css', __FILE__));
}
// use the registered jquery and style above
add_action('wp_enqueue_scripts', 'enqueue_style');
function enqueue_style(){
   wp_enqueue_style( 'bootstrap' );
}

我的文件夹的名称是离职估计器,它只有boot rap文件夹和crotovercalculator.php

我试图调用BTN类,以便在工作时尝试,但仍无法正常工作。

// register jquery and style on initialization
add_action('init', 'register_script');
function register_script() {
    wp_register_style( 'bootstrap', plugins_url('/bootstrap/css/bootstrap.css', __FILE__));
}
// use the registered jquery and style above
add_action('wp_enqueue_scripts', 'enqueue_style');
function enqueue_style(){
   wp_enqueue_style( 'bootstrap' );
}

my folder's name is turnover-calculator it only have the bootrap folder and turnovercalculator.php

i tried to call the btn class to try if it's working but it's still not working.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

高跟鞋的旋律 2025-02-12 13:36:08

您必须使用正确的挂钩,wp_register_stylewp_enqueue_style只能在wp_enqueue_scripts hook hook in ofer Inside 。

请使用此代码:

add_action('init', 'call_scripts');
function call_scripts() {
    add_action('wp_enqueue_scripts', 'enqueue_style');
}


function enqueue_style(){
    wp_register_style( 'bootstrap', plugins_url('/bootstrap/css/bootstrap.css', __FILE__));
    wp_enqueue_style( 'bootstrap' );
}

You have to use the right hooks, wp_register_style and wp_enqueue_style can only be called inside wp_enqueue_scripts hook.

please use this code:

add_action('init', 'call_scripts');
function call_scripts() {
    add_action('wp_enqueue_scripts', 'enqueue_style');
}


function enqueue_style(){
    wp_register_style( 'bootstrap', plugins_url('/bootstrap/css/bootstrap.css', __FILE__));
    wp_enqueue_style( 'bootstrap' );
}
夕嗳→ 2025-02-12 13:36:08

您可以直接在wp_enqueue_scripts回调之类的中直接介绍样式:

add_action( 'wp_enqueue_scripts', 'turnover_calculator_scripts' );
function turnover_calculator_scripts() {
    wp_enqueue_style( 'bootstrap', plugins_url('/bootstrap/css/bootstrap.css', __FILE__));
}

You can just enqueue the style directly inside the wp_enqueue_scripts callback like this:

add_action( 'wp_enqueue_scripts', 'turnover_calculator_scripts' );
function turnover_calculator_scripts() {
    wp_enqueue_style( 'bootstrap', plugins_url('/bootstrap/css/bootstrap.css', __FILE__));
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文