Skip to content

Instantly share code, notes, and snippets.

@andrija-naglic
Last active August 26, 2018 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrija-naglic/94dbbf1ed5c0953d1b88e7d9b047bbaa to your computer and use it in GitHub Desktop.
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
<?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