Title: WordPress Post Date Conditional Script
Last modified: August 30, 2016

---

# WordPress Post Date Conditional Script

 *  [LXXVI](https://wordpress.org/support/users/lxxvi/)
 * (@lxxvi)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/)
 * Before I begin, let me say that I have already scoured this forum looking for
   an existing fix for my issue…
 * Here’s my dilemma. I’m migrating to the newer version of Flowplayer that uses‘
   HTML5’, but I also need the older Flowplayer script to run on older/archived 
   posts created before (August 29th 2015). The problem is that I cannot have both
   new and old scripts running on the same page because they share the same ‘namespace’
   and will create a conflict.
 * This is an example of the old script that I need to run in the header for the
   archived posts:
    `<script src="http://www.mydomain.com/blog/flwplayerfiles/flowplayer-
   3.2.13.min.js"></script>`
 * Does anyone know of…or have a PHP or WordPress script that will display this 
   older Flowplayer .js code in the header if the post was written before the aforementioned
   date?
 * My WordPress URL/permalink formatting is as follows:
    [http://www.mydomain.com/blog/2015/08/30/this-is-an-archived-post/](http://www.mydomain.com/blog/2015/08/30/this-is-an-archived-post/)
 * I’m sure this is a simple script for someone who knows what they’re doing. Your
   help would be greatly appreciated!

Viewing 15 replies - 1 through 15 (of 32 total)

1 [2](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/page/2/?output_format=md)
[3](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/page/2/?output_format=md)

 *  [stephencottontail](https://wordpress.org/support/users/stephencottontail/)
 * (@stephencottontail)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/#post-6493052)
 * You could use [PHP’s DateTime class](http://php.net/manual/en/class.datetime.php).
   It’s available in PHP 5.2 or later. Then you’d probably hook onto `wp_enqueue_scripts()`:
 *     ```
       function sc_load_flowplayer() {
         global $post;
   
         $post_date = new DateTime( get_the_date( null, $post->ID ) );
         $cutoff_date = new DateTime( '2015-08-29' );
   
         if ( is_singular() && ( $post_date < $cutoff_date ) ) {
           wp_enqueue_script( 'older-flowplayer', 'path/to/older/flowplayer.js' );
         } else {
           wp_enqueue_script( 'newer-flowplayer', 'path/to/newer/flowplayer.js' );
         }
       }
       add_action( 'wp_enqueue_scripts', 'sc_load_flowplayer' );
       ```
   
 *  Thread Starter [LXXVI](https://wordpress.org/support/users/lxxvi/)
 * (@lxxvi)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/#post-6493066)
 * stephencottontail,
 * Thanks for that, but unfortunately I don’t know how to hook into wp_enqueue_scripts().
   Though I do follow instructions quite well if you could explain that to me.
 * I tried simply placing your code into the header, bound by php opening and closing
   tags, but I was unable to get the code to work.
 * I’m using php version 5.4.24
 *  [stephencottontail](https://wordpress.org/support/users/stephencottontail/)
 * (@stephencottontail)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/#post-6493100)
 * You should put the code I posted in your child theme’s `functions.php`.
 *  Thread Starter [LXXVI](https://wordpress.org/support/users/lxxvi/)
 * (@lxxvi)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/#post-6493101)
 * I don’t mean to be annoying, but I’m still lost.
 * Could you contact me at [seekjoe@gmail.com](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/seekjoe@gmail.com?output_format=md)?
   I run a rather large blog and I need to get this done quickly. If you could knock
   it out for me, I’d be happy to pay you for your time.
 * Joe
 *  [stephencottontail](https://wordpress.org/support/users/stephencottontail/)
 * (@stephencottontail)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/#post-6493188)
 * What part did you get lost on? Have you read the Codex’s article on child themes:
   [http://codex.wordpress.org/Child_Themes](http://codex.wordpress.org/Child_Themes)?
 *  Thread Starter [LXXVI](https://wordpress.org/support/users/lxxvi/)
 * (@lxxvi)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/#post-6493189)
 * Hi,
 * I really don’t have time to take a crash course in WP scripting. Can you or someone
   contact me so that I can outsource this work? I need to get it done quickly.
 * Thanks!
 *  Thread Starter [LXXVI](https://wordpress.org/support/users/lxxvi/)
 * (@lxxvi)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/#post-6493191)
 * I did successfully create a child theme and I used your script in the child’s
   function.php, but it didn’t do what I want.
 *  [stephencottontail](https://wordpress.org/support/users/stephencottontail/)
 * (@stephencottontail)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/#post-6493192)
 * Can you post the contents of your child theme’s `functions.php` to [Pastebin](http://pastebin.com/)
   and post the link here?
 *  Thread Starter [LXXVI](https://wordpress.org/support/users/lxxvi/)
 * (@lxxvi)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/#post-6493194)
 * Could you contact via email so that we can move this to a more private forum?
 *  [stephencottontail](https://wordpress.org/support/users/stephencottontail/)
 * (@stephencottontail)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/#post-6493195)
 * No. Forum rules are that all support must be kept on the forum. Can you post 
   the contents of your child theme’s `functions.php` to [Pastebin](http://pastebin.com/)
   and post the link here?
 *  Thread Starter [LXXVI](https://wordpress.org/support/users/lxxvi/)
 * (@lxxvi)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/#post-6493196)
 * [http://pastebin.com/wBBZLvuA](http://pastebin.com/wBBZLvuA)
 *  Thread Starter [LXXVI](https://wordpress.org/support/users/lxxvi/)
 * (@lxxvi)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/#post-6493197)
 * I need for that javascript link to conditionally post in the head of the page.
 *  Thread Starter [LXXVI](https://wordpress.org/support/users/lxxvi/)
 * (@lxxvi)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/#post-6493198)
 * For newer posts, nothing should appear.
 *  [stephencottontail](https://wordpress.org/support/users/stephencottontail/)
 * (@stephencottontail)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/#post-6493199)
 * You only need to pass the URL to the JavaScript file to `wp_enqueue_script()`,
   which will correctly format the `<script>` tag for you:
 * `wp_enqueue_script( 'older-flowplayer', 'http://www.SITEURL.com/blog/flwplayerfiles/
   flowplayer-3.2.6.min.js', $in_footer = false );`
 * And since you don’t need to load the older script in some conditions, you can
   remove the rest of the conditional:
 *     ```
       function sc_load_flowplayer() {
         global $post;
   
         $post_date = new DateTime( get_the_date( null, $post->ID ) );
         $cutoff_date = new DateTime( '2015-08-29' );
   
         if ( is_singular() && ( $post_date < $cutoff_date ) ) {
           wp_enqueue_script( 'older-flowplayer', 'http://www.SITEURL.com/blog/flwplayerfiles/flowplayer-3.2.6.min.js', $in_footer = false );
         }
       }
       add_action( 'wp_enqueue_scripts', 'sc_load_flowplayer' );
       ```
   
 *  Thread Starter [LXXVI](https://wordpress.org/support/users/lxxvi/)
 * (@lxxvi)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/#post-6493201)
 * So, I use this in the header?
 *     ```
       <?php
       wp_enqueue_script( 'older-flowplayer', 'http://www.SITEURL.com/blog/flwplayerfiles/flowplayer-3.2.6.min.js', $in_footer = false );
       ?>
       ```
   

Viewing 15 replies - 1 through 15 (of 32 total)

1 [2](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/page/2/?output_format=md)
[3](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/page/2/?output_format=md)

The topic ‘WordPress Post Date Conditional Script’ is closed to new replies.

## Tags

 * [conditional](https://wordpress.org/support/topic-tag/conditional/)
 * [date](https://wordpress.org/support/topic-tag/date/)
 * [script](https://wordpress.org/support/topic-tag/script/)
 * [url](https://wordpress.org/support/topic-tag/url/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 32 replies
 * 2 participants
 * Last reply from: [LXXVI](https://wordpress.org/support/users/lxxvi/)
 * Last activity: [10 years, 9 months ago](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/page/3/#post-6493224)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
