Ecommerce Shopify WordPress Discussion

I'm trying to json_encode an array to a string to set it as a html data attribute but its outputting " instead of speech marks

As the title states, I am trying to pass JSON data from PHP to a HTML data-attribute within a WordPress environment but the rendered data is being outputted with HTML entities " instead of speech marks. Note: this previously worked the function: function build_ga_tracking($category, $label, $action = 'click', $value = '', $event = 'event') { $tracking = array( 'event' => $event, 'category' => $category, 'label' => $label, 'action' => $action, 'value' => $value ); $jsonEncodedTracking = json_encode($tracking); return "data-tracking='".$jsonEncodedTracking."'"; } echo("<li><a href='" . $item->url . "' " . build_ga_tracking('Primary Menu', $cleanTitle, 'Click-'.$cleanTitle) . ">" . $title . "</a></li>"); which outputs as: <li><a href="http://localhost:8080/category/money-tips/" data-tracking="{"event":"event","category":"Primary Menu","label":"Money Tips","action":"Click-Money Tips","value":""}">Money Tips</a></li> note: echo(build_ga_tracking('Primary Menu', $cleanTitle, 'Click-'.$cleanTitle)); outputs correctly: data-tracking='{"event":"event","category":"Primary Menu","label":"Money Tips","action":"Click-Money Tips","value":""}' I've tried using esc_attr() esc_js() and wp_json_encode() with no luck.
This was purely a rendering issue with Chrome dev tools. When inspecting the source code, it's outputting correctly. 2 days of debugging and a massive face palm later.

January 7, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.