Skip to content

Instantly share code, notes, and snippets.

@badcrocodile
Created February 4, 2017 19:38
Show Gist options
  • Save badcrocodile/aede719461fb373be7945849ca9f8eb0 to your computer and use it in GitHub Desktop.
Save badcrocodile/aede719461fb373be7945849ca9f8eb0 to your computer and use it in GitHub Desktop.
One way to add_action ooo style
<?php
namespace IngredientManager;
/**
* Usage: In calling script:
* $enqueue_scripts = new EnqueueScript
*/
class EnqueueScript
{
public function __construct()
{
add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
}
/**
* Enqueue scripts & styles
*
* @return bool
*/
public function enqueue_scripts()
{
// *_version updates version # whenever file is updated to help with caching issues
$js_version = date("ymd-Gis", filemtime(plugin_dir_path(dirname(__FILE__)) . 'Resources/js/scripts.js'));
$css_version = date("ymd-Gis", filemtime(plugin_dir_path(dirname(__FILE__)) . 'Resources/css/styles.css'));
wp_enqueue_script('scripts', plugin_dir_url(dirname(__FILE__)) . 'Resources/js/scripts.js', array('jquery'), $js_version);
wp_enqueue_style('styles', plugin_dir_url(dirname(__FILE__)) . 'Resources/css/styles.css', false, $css_version);
wp_enqueue_script('font-awesome', 'https://use.fontawesome.com/206ac00799.js');
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment