Home > Blockchain >  Bootstrap not working in my custom plugin
Bootstrap not working in my custom plugin

Time:06-09

// 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.

CodePudding user response:

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' );
}

CodePudding user response:

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__));
}
  • Related