You could use PHP’s DateTime class. 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
(@lxxvi)
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
You should put the code I posted in your child theme’s functions.php.
Thread Starter
LXXVI
(@lxxvi)
I don’t mean to be annoying, but I’m still lost.
Could you contact me at [email protected]? 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
What part did you get lost on? Have you read the Codex’s article on child themes: http://codex.ww.wp.xz.cn/Child_Themes?
Thread Starter
LXXVI
(@lxxvi)
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
(@lxxvi)
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.
Can you post the contents of your child theme’s functions.php to Pastebin and post the link here?
Thread Starter
LXXVI
(@lxxvi)
Could you contact via email so that we can move this to a more private forum?
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 and post the link here?
Thread Starter
LXXVI
(@lxxvi)
Thread Starter
LXXVI
(@lxxvi)
I need for that javascript link to conditionally post in the head of the page.
Thread Starter
LXXVI
(@lxxvi)
For newer posts, nothing should appear.
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
(@lxxvi)
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 );
?>