Created
April 2, 2020 15:10
-
-
Save prosantamazumder/aa1973bec1d2b10203308c793b7cf8ff to your computer and use it in GitHub Desktop.
Enqueue Style Scripts Functions.php[ way 1] and Enqueue Style Scripts Create CSS/JS Define Folder [ way 2]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
READ_ME PLEASE | |
YOU CAN USE THE CODE DIRECT FUNCTION.PHP | |
/**================================== | |
* Enqueue scripts and styles way 1. | |
===================================*/ | |
function enqueue_style_scripts() { | |
//EXAMPLE CSS | |
wp_enqueue_style('fancybox', get_template_directory_uri() . '/assets/js/fancybox.css',array(), '1', 'all' ); | |
// For Load Theme main stylesheet. | |
wp_enqueue_style( 'theme_style', get_stylesheet_uri() ); | |
// NO NEED CALL JQUERY LIBRARY BECASUE IT CALL AUTOMATIC | |
//EXAMPLE JS | |
wp_enqueue_script( 'bootstrap', get_template_directory_uri() . '/assets/js/bootstrap-4.0.0.min.js', array('jquery'), '201512218', true ); | |
} | |
add_action( 'wp_enqueue_scripts', 'enqueue_style_scripts' ); | |
?> | |
=============================================================================== | |
<?php | |
READ_ME PLEASE | |
Create file enqueue.php then call it functions.php | |
require get_template_directory().'/inc/enqueue.php'; | |
/**================================== | |
* Enqueue scripts and styles way 2. | |
*===================================/ | |
/** | |
* Theme fonts rendering function | |
* | |
* @author Prosanta Mazumder | |
* @since 0.1.0 | |
* @link https://presstechit-institute.com | |
*/ | |
/** | |
* Defined files path constants | |
* | |
* @since 0.1.0 | |
*/ | |
define( 'WP_QP_CSS_PATH', get_template_directory_uri() . '/assets/css/' ); //DEFINE CSS FOLDER LOCATION | |
define( 'WP_QP_JS_PATH', get_template_directory_uri() . '/assets/js/' ); //DEFINE JS FOLDER LOCATION | |
/** | |
* Enqueue scripts and styles. | |
* | |
* @author Prosanta Mazumder | |
* @since 0.1.0 | |
* @link https://presstechit-institute.com | |
*/ | |
function enqueue_style_scripts_define_folder() { | |
/*---------------------------------------*/ | |
/* CSS Files | |
/*---------------------------------------*/ | |
//bootstrap.css | |
wp_enqueue_style( | |
'bootstrapcss', //SPACIFIC ID | |
WP_QP_CSS_PATH . 'bootstrap.css', //FIELS NAME | |
array(), //DEPENDENCY | |
'0.4.0', //VERSION | |
'all' //MEDIA | |
); | |
/*---------------------------------------*/ | |
/* JS Files | |
/*---------------------------------------*/ | |
//main.js | |
wp_enqueue_script( | |
'mainjs', //SPACIFIC ID | |
WP_QP_JS_PATH . 'main.js', //FIELS NAME | |
array( 'jquery' ), //DEPENDENCY MAIN JQUERY LIBRARY | |
'1.0.0', //VERSION | |
true //MEDIA | |
); | |
} | |
add_action( 'wp_enqueue_scripts', 'enqueue_style_scripts_define_folder' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment