Entonces, no sé si esto es posible, pero quería buscar un objeto window.OneTrust y, si no existe, mantener el atributo como src , de lo contrario, mantenerlo como data-src y cambiar el tipo.
Esto es de lo que estoy hablando:
Si existe window.OneTrust , manténgalo como:
<script type='text/plain' id='google-maps-api-script' className='optanon-category-C0004' data-src="https://maps.googleapis.com/maps/api/js?key=<?php echo get_field('google_maps_api_key', 'option') ?>&v=weekly" ></script>;De lo contrario, tenlo como:
<script type='text/javascript' id='google-maps-api-script' className='optanon-category-C0004' src="https://maps.googleapis.com/maps/api/js?key=<?php echo get_field('google_maps_api_key', 'option') ?>&v=weekly" ></script>;¿Hay alguna manera de que pueda tener un operador ternario para type/src en lugar de hacerlo así?
if (!window.OneTrust) { <script type='text/javascript' id='google-maps-api-script' className='optanon-category-C0004' src="https://maps.googleapis.com/maps/api/js?key=<?php echo get_field('google_maps_api_key', 'option') ?>&v=weekly" ></script>; } else { <script type='text/plain' id='google-maps-api-script' className='optanon-category-C0004' data-src="https://maps.googleapis.com/maps/api/js?key=<?php echo get_field('google_maps_api_key', 'option') ?>&v=weekly" ></script>; }Puede usar document.write en un elemento <script> .
<script> if (!window.OneTrust) { document.write(`<script type='text/javascript' id='google-maps-api-script' class='optanon-category-C0004' src="https://maps.googleapis.com/maps/api/js?key=<?php echo get_field('google_maps_api_key', 'option') ?>&v=weekly" ><\/script>`); } else { document.write(`<script type='text/plain' id='google-maps-api-script' class='optanon-category-C0004' data-src="https://maps.googleapis.com/maps/api/js?key=<?php echo get_field('google_maps_api_key', 'option') ?>&v=weekly" ><\/script>`); } </script>