Skip to content

Instantly share code, notes, and snippets.

@brianhogg
Created March 17, 2016 02:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brianhogg/9de8893b091a56008a0f to your computer and use it in GitHub Desktop.
Save brianhogg/9de8893b091a56008a0f to your computer and use it in GitHub Desktop.
Example of is_new
<?php
/*
Plugin Name: Sample Plugin
Plugin URI: https://brianhogg.com/
Description: Showing is_new
Version: 1.0
Author: Brian Hogg
Author URI: https://brianhogg.com
License: GPLv2 or later
*/
define( 'SAMPLE_VERSION', 1 );
function my_sample_enqueue_script() {
if ( !is_page( 'about' ) )
return;
wp_enqueue_script(
'my-sample-script',
plugins_url( 'js/sample.js', __FILE__ ),
array( 'jquery' ),
SAMPLE_VERSION,
true
);
wp_localize_script(
'my-sample-script',
'sample_data',
array(
'is_new' => strtotime(get_post()->post_date) > strtotime('-7 days'),
)
);
}
add_action( 'wp_enqueue_scripts', 'my_sample_enqueue_script' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment