Page redirect after playing a video

WordPress AI Code Robot

Create WordPress code snippets for free without a developer!

{Name (First):7.3} requested the  following code from my WordPress AI Code Generator.

Page redirect after playing a video

The robot generated the following code:

Below is a WordPress code snippet that can help in redirecting a user to another page after a video is played on the website. We're assuming that you're using a HTML5 video player. We're using JavaScript to redirect the user to another page after the end of the video.

First, let's put JavaScript that listens to the `ended` event and then, redirects to a new page.

“`javascript
<script type="text/javascript">
document.getElementById('yourVideoId').addEventListener('ended', nm_redirectionAfterVideo, false);

function nm_redirectionAfterVideo(e) {
// replace with your desired URL.
window.location.replace("http://yourwebsite.com/another-page");
}
</script>
“`
Replace `'yourVideoId'` with your actual HTML video tag id & replace `"http://yourwebsite.com/another-page"` with your desired redirection URL.

Next, to prefix all functions with `nm`:

Let's assume you have a function named `Page`. The function name with prefix would be `nm_Page`.

Example:

“`php
function nm_Page(){
// your code here
}
“`
This should accomplish the function name prefix and perform the redirection after the video has ended. Be sure to adjust the video id and URL to suit your specific needs.

More
CODE SNIPPETS