Title: Custom plugin not compatible with SG Optimizer
Last modified: April 18, 2023

---

# Custom plugin not compatible with SG Optimizer

 *  Resolved [vidhya1113](https://wordpress.org/support/users/vidhya1113/)
 * (@vidhya1113)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/custom-plugin-not-compatible-with-sg-optimizer/)
 * Hi,
 * I created a custom plugin with the following code, but the times that I am outputting
   through PHP shortcode (which calls a Javascript function in a .js file) are not
   being displayed at the proper place where they are supposed to show up. Instead
   they are displayed at the end of the page (below the footer). This is happening
   due to SG Optimizer. I tested by disabling it’s options like “Defer Render-blocking
   JavaScript”, but with Defer Render-blocking JavaScript enabled, the times doesn’t
   even show up even at the end of the page.
 * Could you please help me out on how to make my custom plugin compatible with 
   SG Optimizer with it’s options enabled?
 * My plugin has the following coed
 *     ```wp-block-code
       <?php
   
       /*
       Plugin Name:  JKY-Custom-Hooks
       Version    :  1.0
       Description:  Demonstrating WordPress Hooks (Actions and Filters) with multiple examples.
       Author     :  Sam
       Author URI :  https://staging59.courses.jkyog.org/
       License    :  GPLv2 or later
       License URI:  https://www.gnu.org/licenses/gpl-2.0.html
       Text Domain:  my-custom-hooks
       */
   
           /**
            * Proper way to enqueue scripts and styles.
            */
           function wpdocs_moment_js_scripts() {
               wp_enqueue_script( 'moment-js', plugins_url('/assets/js/moment-js/moment.min.js', __FILE__ ), array(), '1.0.0', false);
               wp_enqueue_script( 'moment-timezone', plugins_url('/assets/js/moment-js/moment-timezone.min.js', __FILE__ ), array(), '1.0.0', false);
               wp_enqueue_script( 'moment-timezone-data', plugins_url('/assets/js/moment-js/moment-timezone-with-data.min.js', __FILE__ ), array(), '1.0.0', false);
               wp_enqueue_script( 'moment-timezone-tenyears', plugins_url('/assets/js/moment-js/moment-timezone-with-data-10-year-range.min.js', __FILE__ ), array(), '1.0.0', false);
               wp_enqueue_script( 'moment-timezone-nineteenseventy', plugins_url('/assets/js/moment-js/moment-timezone-with-data-1970-2030.min.js', __FILE__ ), array(), '1.0.0', false);
           }    
       add_action( 'wp_enqueue_scripts', 'wpdocs_moment_js_scripts' );
   
       add_action( 'wp_enqueue_scripts', 'wp_custom_plugin_js_scripts' );
       function wp_custom_plugin_js_scripts() {
           //wp_register_script( 'my-custom-hooks', plugins_url( '/assets/js/custom-date-scripts.js' , __FILE__ ),array('jquery'),1.0);
           wp_enqueue_script('custom-date-scripts', plugins_url( '/assets/js/custom-date-scripts.js' , __FILE__ ));
       }
   
       function wpb_hook_get_client_timezonetime($attr) {
           $input_arr = shortcode_atts( array(
       					'input_time' => '5:00 PM',
                           'input_timezone' => 'CST'
       				), $attr);
           //wp_enqueue_script( 'my-custom-hooks' );
           return "<script type='text/javascript'>get_client_time( '". $input_arr['input_time'] ."', '". $input_arr['input_timezone'] ."' );</script>";
       }
       add_shortcode('get_client_timezonetime', 'wpb_hook_get_client_timezonetime');
   
       //=================================================
       // Security: Abort if this file is called directly
       //=================================================
       if ( !defined('ABSPATH') ) { 
           die;
       }
   
       ?>
       ```
   
 * My .js file has the following code:
 *     ```wp-block-code
       	function get_client_time($input_time, $input_timezone) {
   
                   var dt = moment($input_time, ["h:mm A"]).format("HH:mm");               
                   var splitTime = dt.split(/:/)
                   var full_date = moment(new Date().setHours(splitTime[0], splitTime[1], 0)).tz("America/Chicago", true);
   
       		var dateTime = moment(full_date).format("YYYY-MM-DD h:mm:ss a");
   
                   var local_dateTime = moment(full_date).tz(moment.tz.guess()).format("YYYY-MM-DD h:mm:ss a");
                   var local_time = moment(full_date).tz(moment.tz.guess()).format("h:mm a z");
                   console.log("local date time: " + local_dateTime);
                       console.log($input_time);
                       console.log($input_timezone);
       		var result = "<span style='color: #DA4505; font-size: 16px; font-weight: 600; font-style: italic; display: block; text-align: center'>" + local_time + "</span>";
                       document.write(result);
                       //return result;
                   }
       ```
   
 * Please help me in making this work.
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fcustom-plugin-not-compatible-with-sg-optimizer%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Moderator [t-p](https://wordpress.org/support/users/t-p/)
 * (@t-p)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/custom-plugin-not-compatible-with-sg-optimizer/#post-16666200)
 * > This is happening due to SG Optimizer.
 * Du you mean [SiteGround Optimizer](https://wordpress.org/plugins/sg-cachepress/)
   
   By SiteGround
 * If so, try asking at that plugin’s dedicated support. They may have an easy solution.

Viewing 1 replies (of 1 total)

The topic ‘Custom plugin not compatible with SG Optimizer’ is closed to new replies.

## Tags

 * [custom plugin](https://wordpress.org/support/topic-tag/custom-plugin/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [t-p](https://wordpress.org/support/users/t-p/)
 * Last activity: [3 years, 1 month ago](https://wordpress.org/support/topic/custom-plugin-not-compatible-with-sg-optimizer/#post-16666200)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
