frontity/wp-plugins

REST API - Head Tags adding scripts to wp-json

Closed this issue · 6 comments

Affected Plugin

REST API - Head Tags for WordPress

Description

When accessing /wp-json/wp/v2/pages on mobile (with the user agent header) the plugin is adding some scripts to the response which causes the JSON parser to crash.

The script is added multiple times when the user-agent header is of mobile device

<script>navigator.userAgent.match(/iPad|iPhone|iPod/i) != null && window.name != '' && top.location != window.location && (top.location.href = window.location.href);</script>

When the user-agent is on desktop evreything seems to be working fine.

Reproduce

Access https://architects-seattle.com/wp-json/wp/v2/posts when developer tools is open and the device emulation is turned on for a mobile device.

Are you sure it's this plugin's fault? It doesn't have any userAgent related code.

When I disabled the plugin it didn't add the script tags, when I'm accessing it from desktop with the plugin enabled it does not add the tag. The only thing that is different is the user agent header.

Have you tried with the rest of your plugins disabled?

No, but it's only happening when the plugin is activated, when I'm disabling it the wp-json is working perfectly

Could you please try?

Ok I don't know what happened, disabling the head tags plugin did remove the tags and enabling it brought them back.
I disabled ThemeREX Addons plugin and it also removed the tags, after enabling it back the tags were not there anymore.
Don't know if this worth checking or not.
Anyway the problem is now solved.