• patrick_here

    (@patrick_here)


    I notice that if I have one post with a video, the video.js file will be loaded not just on that post but on all posts on the site. So if my WordPress site has 100 posts and I add a video to one of those posts then the other 99 posts will load that (unnecessary) javascript file. Is there a way to change it so that the javascript file will only load on posts that actually use it?

    I’m really looking for a way that doesn’t require the user to write new php code whenever a new video is added to a specific post.

    Thanks for this plugin. It’s very useful.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter patrick_here

    (@patrick_here)

    The fix for this bug is rather simple. The calls to wp_enqueue_script() in your videojs_html5_player_enqueue_scripts() function simply need to be wrapped in a ‘has_shortcode()’ block. I have included the code for the fix below (approx line 170 of the plugin file); I recommend that you do a new release and include this fix.

    global $post;
    if ( isset( $post->post_content ) && has_shortcode( $post->post_content, 'videojs_video' ) ) {
    wp_enqueue_script('videojs');
    wp_enqueue_style('videojs');
    }


    Plugin Author Noor Alam

    (@naa986)

    Hi, Thanks for the feedback. This feature has been added.

    xellagm

    (@xellagm)

    Hello ! I see that you added this feature to choose in settings if we want to Load Scripts Globally or not, which is a great idea for performance, but I’ve got an issue with that new functionnality, I load a video in my <header> section with a custom code :

    print do_shortcode('[videojs_video id="homevideo" url="..."]);

    The thing is that this part of the page is not saved in post->post_content datas, so my video was not loading as the script was not added because the shortcode was not founded in the code.

    Could you, maybe, add a filter or action to choose in our functions.php to force adding the JS and CSS of the plugin on specific page, for exemple :

    add_filter('active_videojs_assets', 'my_custom_function');
    function my_custom_function() {
    if ( basename(get_page_template()) == "homepage.php" ) :
    return true;
    else :
    return false;
    endif;
    }

    Something like that, so we can manually add script in specific pages of our theme.

    Thank you !

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.