Ecommerce Shopify WordPress Discussion

Add custom comment to wordpress script in source code

I want to add a comment inside my script so that whenever I view page source I can see that comment. The code I have is: public function front_scripts() { // Make sure that the GA ttracking code is being included if ( 'on' === $GLOBALS['WP_ANALYTIFY']->settings->get_option( 'install_ga_code', 'wp-analytify-profile', 'off' ) ) { global $current_user; $roles = $current_user->roles; if ( ! isset( $roles[0] ) or ! in_array( $roles[0], $GLOBALS['WP_ANALYTIFY']->settings->get_option( 'exclude_users_tracking', 'wp-analytify-profile', array() ) ) ) { wp_enqueue_script( 'analytify-events-tracking', plugins_url( 'assets/js/analytify-events-tracking.min.js', __DIR__ ), array( 'jquery' ) ); add_filter( 'script_loader_tag', array( $this, 'add_script_comment_to_tracking_min' ), 10, 3 ); wp_localize_script( 'analytify-events-tracking', 'analytify_events_tracking', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'tracking_mode' => ANALYTIFY_TRACKING_MODE, 'ga_mode' => method_exists( 'WPANALYTIFY_Utils', 'get_ga_mode' ) ? WPANALYTIFY_Utils::get_ga_mode() : 'ga3', 'tracking_code' => WP_ANALYTIFY_FUNCTIONS::get_UA_code(), 'is_track_user' => analytify_is_track_user(), 'root_domain' => $this->get_root_domain(), 'affiliate_link' => $GLOBALS['WP_ANALYTIFY']->settings->get_option( 'affiliate_link_path', 'wp-analytify-events-tracking', '' ), 'download_extension' => $GLOBALS['WP_ANALYTIFY']->settings->get_option( 'file_extension', 'wp-analytify-events-tracking', 'zip|mp3*|mpe*g|pdf|docx*|pptx*|xlsx*|rar*' ), 'anchor_tracking' => $GLOBALS['WP_ANALYTIFY']->settings->get_option( 'anchor_tracking', 'wp-analytify-events-tracking' ), ) ); } } } And the way I want the comment to be is: <script id="analytify-events-tracking-js-extra"> /* the comment to be shown. */ var analytify_events_tracking = {"ajaxurl":"http:\/\/analytify-github.local\/wp-admin\/admin-ajax.php","tracking_mode":"gtag","ga_mode":"ga4","tracking_code":"G-PF9VK8TRF6","is_track_user":"1","root_domain":"analytify-github.local","affiliate_link":[{"path":"https:\/\/wpbrigade.com\/?edd_action=add_to_cart&download_id=1835&edd_options%5Bprice_id%5D=4&_gl=1*bzfdf6*_ga*ODA1Mzc5NjgyLjE3MDM2ODA1MzM.*_ga_YCW7CRBRMF*MTcwNDM2NjA2Ny4xMi4wLjE3MDQzNjYxMTkuOC4wLjA.","label":"test"}],"download_extension":"zip|mp3*|mpe*g|pdf|docx*|pptx*|xlsx*|rar*","anchor_tracking":"on"}; </script> I have used following way to add the comment but in it another script is generated: $comment = "Your comment here"; wp_script_add_data('analytify-events-tracking', 'data', $comment); but in this another script is created. How to fix this?
The analytify plugin has already enqueued the script, so your code is enqueueing it a second time. Before your call to wp_enqueue_script, try adding: wp_dequeue_script( 'analytify-events-tracking' ); which should work if the plugin has already enqueued the script when front_scripts runs.

January 17, 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.