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 - 16 through 30 (of 32 total)

[←](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/?output_format=md)
[1](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/?output_format=md)
2 [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/3/?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/page/2/#post-6493202)
 * No. You can copy and paste the updated function I posted into your child theme’s`
   functions.php`, replacing the function that was already there. `wp_enqueue_script()`
   will automatically format the `<script>` tag for you and place it in the appropriate
   place.
 *  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/page/2/#post-6493203)
 * I understand now.
 * So I did that, but the script isn’t showing up in the source code of the older,
   pre-8/29 posts.
 *  [stephencottontail](https://wordpress.org/support/users/stephencottontail/)
 * (@stephencottontail)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/page/2/#post-6493206)
 * What do you have in your child theme’s `functions.php` now?
 *  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/page/2/#post-6493207)
 *     ```
       <?php
       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' );
       ?>
       ```
   
 *  [stephencottontail](https://wordpress.org/support/users/stephencottontail/)
 * (@stephencottontail)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/page/2/#post-6493208)
 * At the risk of sounding insulting, are you actually using `www.SITEURL.com` in
   your file? Does Flowplayer require jQuery? Can you post a link to your site?
 *  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/page/2/#post-6493209)
 * I’m leaving it as SITEURL for now just to see if the jscript shows up or not.
   If the wordpress script that you are helping me with works, then I’ll fully implement
   it.
 *  [stephencottontail](https://wordpress.org/support/users/stephencottontail/)
 * (@stephencottontail)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/page/2/#post-6493212)
 * The reason the script isn’t showing up in the header is because WordPress can’t
   find the JS file. You need to pass the correct location to the JS file.
 *  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/page/2/#post-6493213)
 * I just put the full, correct jscript url in there and it’s still not showing 
   up in the live site’s source code.
 *  [stephencottontail](https://wordpress.org/support/users/stephencottontail/)
 * (@stephencottontail)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/page/2/#post-6493214)
 * What do you have now in your child theme’s `functions.php`? Can you post a link
   to your site?
 *  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/page/2/#post-6493215)
 * It’s an adult site and I would rather keep that private.
 *  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/page/2/#post-6493216)
 * I have the same thing I posted to you earlier in my functions.php file, just 
   with SITEURL replaced with the actual URL.
 *  [stephencottontail](https://wordpress.org/support/users/stephencottontail/)
 * (@stephencottontail)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/page/2/#post-6493217)
 * Does it work if you replace
 * `if ( is_singular() && ( $post_date < $cutoff_date ) ) {`
 * with
 * `if ( $post_date < $cutoff_date ) {`
 *  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/page/2/#post-6493218)
 * No.
 *  [stephencottontail](https://wordpress.org/support/users/stephencottontail/)
 * (@stephencottontail)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/page/2/#post-6493220)
 * I just noticed you have `/blog/flwplayerfiles/` in the path to the JS. Could 
   that be a typo for `/blog/flowplayerfiles/` instead?
 * I’m sorry, but I’m running out of ideas for things I can check without looking
   at the site itself. For what it’s worth, you are allowed to post links to NSFW
   sites, if they’re clearly marked as such, but if you’re still not comfortable
   with posting a link to your site, you might be better off posting at [http://jobs.wordpress.net](http://jobs.wordpress.net/)
   instead.
 *  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/page/2/#post-6493222)
 * flwplayerfiles is correct.

Viewing 15 replies - 16 through 30 (of 32 total)

[←](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/?output_format=md)
[1](https://wordpress.org/support/topic/wordpress-post-date-conditional-script/?output_format=md)
2 [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/3/?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
