php - How to make the YouTube player from embedded iframe work and not block the page load in Chrome?

I have a web page with this code in it (hidden by default withdisplay: none
ancestor) (please see the screenshots below):
<iframe width="560" height="315" src="https://www.youtube.com/embed/YAGuGFpeIJA" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
The YouTube API calls timeout and in plus my Chrome browser gets blocked (the DevTools cannot be opened in that tab - to make the screenshots I had to open the DevTools before navigating to that web page; the context menu on the page content does not get opened). The code runs on a local Docker container. I believe the issue is linked to the URL of the web page, because the issue happens only after putting this code at the end of my WordPress theme'sfunctions.php
:
add_action('rewrite_rules_array', 'rewrite_rules');
function rewrite_rules($rules) {
$new_rules = array(
'/ro/.*$' => 'index.php',
'/en/.*$' => 'index.php'
);
return $rules + $new_rules;
}
This page sent me here. This is a previous question in the same "series".
Update: The page is still blocked if I remove the src attribute of the iframe, but at least the spinner starts to fade-out. It fades out just partially, and then again I cannot open DevTools in the usual manner. In the Network tab of DevTools I see that it may be a WP REST API call that is the problem:
Below are just the screenshots - the last part of the actual question.
Thank you.
Screenshots
1
2
3
4
5
6
7
8
9
10
Answer
Solution:
I do not know the exact cause and how it should behave ideally, but to solve this in my case I just had to do this:
Furthermore, permalinks will need to be refreshed (you can do this from your admin under (Settings > Permalinks) before the rewrite changes will take effect.
(step taken from https://codex.wordpress.org/Rewrite_API)
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: using $this when not in object context
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.