Last active
March 5, 2024 10:44
-
-
Save ravismakwana/b25e0d9137fd1cfeab5ad2d1bb299272 to your computer and use it in GitHub Desktop.
Enqueue Scripts and styles with timestamp versioning in WordPress.
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 | |
/* Use this when parent theme used */ | |
wp_register_style('main-css', untrailingslashit( get_template_directory_uri() ).'css/main.css', ['bootstrap'], filemtime(untrailingslashit( get_template_directory() ).'css/main.css'), 'all'); | |
wp_enqueue_style('main-css'); | |
wp_register_script('main', untrailingslashit( get_template_directory_uri() ).'js/main.js', ['jquery', 'slick-slider'], filemtime(untrailingslashit( get_template_directory() ).'js/main.js'), true); | |
wp_enqueue_script('main'); | |
/* Use this when child theme used */ | |
wp_register_style('main-css', untrailingslashit( get_stylesheet_directory_uri() ).'css/main.css', ['bootstrap'], filemtime(untrailingslashit( get_stylesheet_directory() ).'css/main.css'), 'all'); | |
wp_enqueue_style('main-css'); | |
wp_register_script('main', untrailingslashit( get_stylesheet_directory_uri() ).'js/main.js', ['jquery', 'slick-slider'], filemtime(untrailingslashit( get_stylesheet_directory() ).'js/main.js'), true); | |
wp_enqueue_script('main'); | |
/* | |
<h5>More Information</h5> | |
The returning path does not contain a trailing slash. | |
An example output of get_stylesheet_directory() is /home/user/public_html/wp-content/themes/my_theme | |
In the event a child theme is being used, that is the directory that will be returned, not the parent theme directory (use get_template_directory() instead if you want the parent directory). | |
To retrieve the URI of the stylesheet directory use get_stylesheet_directory_uri() | |
To retrieve the path of a parent theme, use get_template_directory() | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment