I am creating a wordpress plugin, where I need to include multiple stylesheets and JS files.

I have used the following code,

1. TRIAL 1- Including styles and scripts together

define( 'DELTA__PLUGIN_URL', plugin_dir_url( __FILE__ ) );
add_action('wp_enqueue_scripts', 'imwi_scripts'); 
    function imwi_scripts() {
        wp_register_style( 'delta-styles', DELTA__PLUGIN_URL . "../include-multiple-stylesheets-in-wordpress-plugin/css/style.css" );
        wp_register_style( 'delta-styles', DELTA__PLUGIN_URL . "../include-multiple-stylesheets-in-wordpress-plugin/css/jquery.dataTables.css" );
        wp_register_style( 'delta-styles', DELTA__PLUGIN_URL . "../include-multiple-stylesheets-in-wordpress-plugin/css/font-awesome.min.css" );
        wp_register_script( 'delta-scripts', plugins_url('../js/jquery.dataTables.js', __FILE__) , array('jquery'), true );
        wp_enqueue_style( 'delta-styles' );
        wp_enqueue_script( 'delta-scripts' );
    }

2. TRIAL 2-Including scripts and styles seperately

define( 'DELTA__PLUGIN_URL', plugin_dir_url( __FILE__ ) );
//EN-QUEUING JAVASCRIPTS
add_action('wp_enqueue_scripts', 'imwi_scripts'); 
    function imwi_scripts() {
        wp_register_script( 'delta-scripts', plugins_url('../js/jquery.dataTables.js', __FILE__) , array('jquery'), true );
        wp_enqueue_script( 'delta-scripts' );
    }
//EN-QUEUING STYLES
add_action("wp_enqueue_scripts", "imwi_styles");
    function imwi_styles() {
        wp_register_style( 'delta-styles', DELTA__PLUGIN_URL . "../include-multiple-stylesheets-in-wordpress-plugin/css/style.css" );
        wp_register_style( 'delta-styles', DELTA__PLUGIN_URL . "../include-multiple-stylesheets-in-wordpress-plugin/css/jquery.dataTables.css" );
        wp_register_style( 'delta-styles', DELTA__PLUGIN_URL . "../include-multiple-stylesheets-in-wordpress-plugin/css/font-awesome.min.css" );
        wp_enqueue_style( 'delta-styles' );
    }

RESULT
1. jquery.dataTables.js and style.css is getting enqueued in the page successfully.

PROBLEM:

  1. jquery.dataTables.css and font-awesome.min.css didnot get included.

  2. I want to keep my styles seperate, so I can’t import my stylesheets into a single stylesheet (say delta.css) and en-queue the delta.css through wp_enqueue_style().

  3. Use of CDN is not possible, because [WordPress.org Plugins] mailed back with this response Offloading images, js, css, cgi, and other scripts to Google (or jquery.com or anywhere else frankly) is disallowed because you’re introducing an unnecessary dependency on another site.

QUESTION: Is it possible to include all the scripts and styles without creating multiple functions per stylesheet and script?

Thank you for helping..

Read more here: Include Multiple Stylesheets in WordPress Plugin


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , ,

Wordpress related questions and answers: