• Hi, I’m looking for a hook to set the preload parameter to “auto” for the videos of all my playlists. I use the wp native [playlist] shortcode.

    The first objective is to avoid the waiting time when clicking on play. The second objective is to show the first frame of the video as a cover, in place of the black frame I currently have. Only IE is managing to show the first frame of the videos and, for once, it looks much better on IE!

    Looking at the codex, the preload parameter doesn’t exist for the playlist shortcode, but only for the video shortcode. In this last case, the defaut value for preload is metadata.

    This is the current output I have using the wp native [playlist] shortcode:
    <video preload="none" src="https://example.com/wp-content/uploads/2016/12/video.mp4" style="width: 100%; height: 100%;" height="258" width="470"></video>

    Any help would be welcome.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    You can use the “post_playlist” filter to generate your own output. Your callback is passed all the attributes included with the shortcode, as well as an ID number unique to this shortcode instance. Whatever your callback returns is output in place of the shortcode.

    Returning something with this filter completely bypasses the normal shortcode handler, you are on your own with composing the output. You could pretty much copy the wp_playlist_shortcode() function declaration, altering it as needed for the preload parameter. Or make a custom shortcode using the altered wp_playlist_shortcode() code as the new shortcode handler. Change the function and shortcode names of course.

    I know this is a lot of code just to alter one parameter, but it’s all that’s available right now. At least something is possible without doing a dirty hack by altering core code.

    Thread Starter hugodebe

    (@hugodebe)

    Thanks for your reply. To help me understand, using the post_playlist filter will have the same result than recreating the shortcode?

    remove_shortcode('playlist');
    add_shortcode('playlist', 'my_custom_playlist_shortcode');

    In both methods I have to copy all the code to customize the output, right? Is the filter a better approach than recreating the shortcode and why?

    Moderator bcworkz

    (@bcworkz)

    There’s little difference really. The advantage is minor. With the filter you need not be concerned with ensuring the shortcode has been established before removing it. You can hook the filter pretty much anytime without concern for timing your code execution.

    Generally speaking, filters are usually a big advantage over remove and replace, but certain filters like this are “override” filters where that advantage diminishes greatly. Filter and action hooks are the normal way of customizing WP. Remove and replace could be thought of as being more “hacky”, but can work equally well.

    Either way, you don’t necessarily copy all the code. WP code needs to address many potential situations. Your code can be specific to your situation and be more efficient. I suggested copying only because it’s the easiest way to make a minor change without developing the entire process.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to set preload=”auto” by defaut for native video playlists’ is closed to new replies.