Forums » Fixing WordPress » 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/

    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)
  • 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

    (@lxxvi)

    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.

    What do you have in your child theme’s functions.php now?

    Thread Starter LXXVI

    (@lxxvi)

    <?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' );
    ?>

    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

    (@lxxvi)

    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.

    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

    (@lxxvi)

    I just put the full, correct jscript url in there and it’s still not showing up in the live site’s source code.

    What do you have now in your child theme’s functions.php? Can you post a link to your site?

    Thread Starter LXXVI

    (@lxxvi)

    It’s an adult site and I would rather keep that private.

    Thread Starter LXXVI

    (@lxxvi)

    I have the same thing I posted to you earlier in my functions.php file, just with SITEURL replaced with the actual URL.

    Does it work if you replace

    if ( is_singular() && ( $post_date < $cutoff_date ) ) {

    with

    if ( $post_date < $cutoff_date ) {

    Thread Starter LXXVI

    (@lxxvi)

    No.

    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 instead.

    Thread Starter LXXVI

    (@lxxvi)

    flwplayerfiles is correct.

Viewing 15 replies - 16 through 30 (of 32 total)
  • The topic ‘WordPress Post Date Conditional Script’ is closed to new replies.