0

I have this code in a plugin

class DashboardCustomizer {

    public function __construct()
    {
        add_action( 'admin_enquque_scripts', array( $this, 'load_custom_scripts' ) );
    }

    /*
    * Carico dipendenze CSS e JS da CDN
    */
    public function load_custom_scripts()
    {
        wp_enqueue_style( 
            'bs-css', 
            'https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css', 
            array(), 
            false,  
        );
        wp_register_style( 'bs-css' );

        wp_enqueue_script( 
            'popper-js', 
            'https://unpkg.com/@popperjs/core@2', 
            array(), 
            false, 
            false 
        );
        wp_register_script( 'popper-js' );

        wp_enqueue_scritp(
            'bs-js',
            'https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js',
            array( 'popper-js' ),
            false,
            false
        );
        wp_register_script( 'bs-js' );
        
    }
}

new DashboardCustomizer();

I'm trying to load some scripts from CDN but when I inspect the page it seems that they are not loaded. Is there something wrong with the code?

5
  • 1
    You have some typos in the code above, including the hook and some of the enqueue functions. If this is exactly what you're running, those would prevent it from working as you expect. If not, you may want to update the code block here so others can help.
    – WebElaine
    Sep 6, 2023 at 14:26
  • Yes I see and fixed in the dev code. Just a question, if I want to load a css from a subfolder inside my plugin folder is the plugins_url(__FILE__) correct?
    – ICTDEV
    Sep 6, 2023 at 14:32
  • 1
    Yes - you can see examples in the Developer Resources - developer.wordpress.org/reference/functions/plugins_url/…
    – WebElaine
    Sep 6, 2023 at 20:38
  • 1
    As @WebElaine said, you've misspelled things: add_action( 'admin_enquque_scripts' is incorrect, for example, that's not the name of the action. It should be admin_enqueue_scripts - WordPress has no idea what to do with your action. You also have wp_enqueue_scritp, the t and the p are in the wrong order. Sep 6, 2023 at 23:23
  • Thank you for the help. Feel free to leave an answer so I can accept it.
    – ICTDEV
    Sep 7, 2023 at 7:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.