Last active
August 26, 2018 14:22
-
-
Save andrija-naglic/94dbbf1ed5c0953d1b88e7d9b047bbaa to your computer and use it in GitHub Desktop.
My way to enqueue scripts in WordPress and load from cache only if the file is not changed
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 | |
// In plugins | |
// ---------- | |
$and_js_ver = date("ymd-Gis", filemtime( plugin_dir_path( __FILE__ ) . 'js/main.js' )); | |
wp_enqueue_script( 'and_js', plugins_url( 'js/main.js', __FILE__ ), array(), $and_js_ver ); | |
$and_css_ver = date("ymd-Gis", filemtime( plugin_dir_path( __FILE__ ) . 'style.css' )); | |
wp_register_style( 'and_css', plugins_url( 'style.css', __FILE__ ), array(), $and_css_ver ); | |
wp_enqueue_style( 'and_css' ); | |
// in themes use: get_template_directory() / get_template_directory_uri() | |
// in child themes use: get_stylesheet_directory() / get_stylesheet_directory_uri() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment