You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Load custom scripts in iframe of editor in FSE and mobile review #41065
Currently I can't find any details how to load scripts inside iframe and I see only styles there. Scripts are loaded in admin pages, but it's very common scenarios when we need also scripts inside iframe. For example, for libraries, which are detecting scroll positions. Placing such scripts outside iframe makes them inaccurate for work
@justintadlock No, it's not the same. I don't have problem in loading files. Problem is that they are loaded on page but outside iframe. I want to suggest some hook for possibility to load something inside iframe.
Allowing enqueue_block_editor_assets to work inside iframe can help, but as I understand from comments, this hook is used only for Editor panels and not supposed to work in content area of editor
Reacted by Ivan Hryhorenko, Paul Ryley, Falko, Collin S. Versluis and Syed Abrar Ahmed Shah
From my digging, It seems you can load <style> inside the iframe, but not <script>. In my case, I was using Ionicons 5 which requires a <script> to load font icons. The font icons wouldn't load inside a mobile preview and FSE screen since those pages get loaded through an iframe. Despite my best efforts, I could not find a way to hack it either. I had to revert to using a font file version of Ionicons to load the fonts inside the iframe.
Reacted by Ivan Hryhorenko, Syed Abrar Ahmed Shah, Jamie Sanchez, Dawid Szpecht and Trevor Robertson
However, regarding the script, I really don't recommend loading editing UI in the iframe. Instead, you should probably render a block preview inside the block and make the user edit the block settings in a modal, or in the block inspector.
Let's close this issue, but feel free to create a new issue if your have additional questions or concerns with the new API.
Activity
justintadlock commentedon May 24, 2022
@wpsoul - Can you verify if the following issue is the same that you're experiencing? #38673
If so, we can close this ticket out in favor of the existing one.
wpsoul commentedon May 24, 2022
@justintadlock No, it's not the same. I don't have problem in loading files. Problem is that they are loaded on page but outside iframe. I want to suggest some hook for possibility to load something inside iframe.
Allowing enqueue_block_editor_assets to work inside iframe can help, but as I understand from comments, this hook is used only for Editor panels and not supposed to work in content area of editor
webplantmedia commentedon Jan 2, 2023
From my digging, It seems you can load <style> inside the iframe, but not <script>. In my case, I was using Ionicons 5 which requires a <script> to load font icons. The font icons wouldn't load inside a mobile preview and FSE screen since those pages get loaded through an iframe. Despite my best efforts, I could not find a way to hack it either. I had to revert to using a font file version of Ionicons to load the fonts inside the iframe.
jordesign commentedon Sep 12, 2023
This appears to now be resolved - adding the note added to #47924 for details - and will close it.