Skip to content

Add Filter to Show Cover Image When Self-Hosted Video Ends#2292

Open
Misplon wants to merge 2 commits intodevelopfrom
fix/video-show-poster-on-end
Open

Add Filter to Show Cover Image When Self-Hosted Video Ends#2292
Misplon wants to merge 2 commits intodevelopfrom
fix/video-show-poster-on-end

Conversation

@Misplon
Copy link
Member

@Misplon Misplon commented Mar 6, 2026

Summary

  • Adds a sow_video_show_cover_on_end filter (defaults to false) that, when enabled, resets a self-hosted video back to its poster/cover image after playback ends instead of freezing on the last frame.
  • Users can enable it with add_filter( 'sow_video_show_cover_on_end', '__return_true' );

How it works

  • The filter adds a data-show-cover-on-end attribute to the <video> element via the existing $video_args array.
  • The JS listens for the ended event and calls video.load() to reset the player to its initial state, re-displaying the poster image.

Test plan

  • Add a self-hosted video with a cover image, confirm default behavior is unchanged (freezes on last frame)
  • Enable the filter and confirm the video resets to the cover image after playback ends
  • Confirm it works with both MediaElement.js controls and hidden controls
  • Confirm loop still takes priority (looped videos don't fire ended)

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Misplon Misplon requested a review from AlexGStapleton March 6, 2026 11:57
@Misplon Misplon changed the title Add filter to show cover image when self-hosted video ends Add Filter to Show Cover Image When Self-Hosted Video Ends Mar 14, 2026
@AlexGStapleton
Copy link
Member

I'm having trouble getting both widgets/video/js/so-video-widget.js to output (it has a specific set of requirements) and the show-cover-on-end attribute present. What is the required settings combination, and is that combination a little too strict? It might be worth altering the so-video-widget.js changes to allow for it to be output with more settings combinations (will require JS adjustments to prevent issues).

@Misplon
Copy link
Member Author

Misplon commented Mar 18, 2026

@AlexGStapleton

You were right. The requirements were too strict.

Before this change, the filter would only work when so-video-widget.js was already being loaded, which for self-hosted videos effectively meant a fairly narrow combination of settings such as hidden controls or FitVids being enabled.

I have loosened that now in e5845b2e. If sow_video_show_cover_on_end returns true for a self-hosted video, we also enqueue so-video-widget.js, so the poster reset behavior is no longer tied to that smaller set of settings.

I also adjusted the JS initialization so repeated setup_widgets calls only initialize new video elements and do not reinitialize existing ones.

That should make the filter work with the normal self-hosted video setup as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants