Created
March 17, 2016 02:30
-
-
Save brianhogg/9de8893b091a56008a0f to your computer and use it in GitHub Desktop.
Example of is_new
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 | |
/* | |
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