Before submitting an issue please check that you’ve completed the following steps:
Describe the bug
When a Google font is used in Jetmenu settings, and Combine Google Fonts is enabled at WP Rocket, JetMenu will add its own google font tag. If the theme already has another google font tag, the combined file will get injected twice at the HTML, the usual injection and another one inside JetMenu _data-menu-options_ object, breaking the menu functionality.
To Reproduce
Steps to reproduce the behavior:
To Reproduce (if you don't have a copy of JetMenu)
Steps to reproduce the behavior:
Expected behavior
Enabling Combine Google Fonts shouldn't break the menu functionality
Screenshots

Additional Information
Related HS Ticket: https://secure.helpscout.net/conversation/1141442668/159225?folderId=2683093
Backlog Grooming (for WP Media dev team use only)
Reproduce the issue ✅
Identified this issue on localhost.
Identify the root cause ✅
The root cause is that JetMenu contains SVG which contains <title></title> and Google Fonts is appended after </title> in here:
https://github.com/wp-media/wp-rocket/blob/57003cff362df710d36acb49085115ea4d09e0eb/inc/Engine/Optimization/GoogleFonts/Combine.php#L79
Scope a solution ✅
The solution will be to exclude the replace when
There is also the possibility to use preg_replace instead of str_replace and use the limit attribute to perform the insertion only once.
Since we want to target the </title> tag in the <head>, it's very unlikely that another closing tag would be before the one for the page.
As @Tabrisrp said, we need to target within the <head> element only. How can we do that?
DomDocument to get the <head> and then insert after the <title> element.</title> within the <head></head>.Either approach should work.
Because in here there are multiple ways of doing this I was checking on how it should be done.
I would go on targeting with regex </title> withing <head></head>.
Does this sound good?
thatt's the best approach I think yes
For now, we'll stick with regex. I'm starting a R&D project to investigate using DomDocument with regex fallback for malformed HTML. But until we have that design built and tested, let's stick with regex.