Title: echo used in wp_enqueue_scripts
Last modified: August 15, 2024

---

# echo used in wp_enqueue_scripts

 *  [Antony Booker](https://wordpress.org/support/users/antonynz/)
 * (@antonynz)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/echo-used-in-wp_enqueue_scripts/)
 * This plugin is using echo within the wp_enqueue_scripts function in the code 
   below found in the modules/enqueue/plus-generator.php file:
 *     ```wp-block-code
       public function load_inline_script(){
           $js_inline1 = 'var theplus_ajax_url = "'.admin_url("admin-ajax.php").'";
           var theplus_ajax_post_url = "'.admin_url("admin-post.php").'";
           var theplus_nonce = "'.wp_create_nonce("theplus-addons").'";';
           echo wp_print_inline_script_tag($js_inline1);  
       }
       ```
   
 * This is creating an issue with the default wp-sitemap.xml (as it’s being outputted
   there). The wp_enqueue_script function isn’t actually designed for echoing output
   to and should be for enqueuing scripts and styles.
   In the code above the wp_print_inline_script_tag
   function is actually a filter, and likely added mistakenly instead of wp_add_inline_script.
   Can this please be changed to follow the intended use of wp_enqueue_scripts to
   enqueue that inline script to help prevent issues with the echoing of that code
   prematurely?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Support [Divyang Chaudhary](https://wordpress.org/support/users/divyangposimyth/)
 * (@divyangposimyth)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/echo-used-in-wp_enqueue_scripts/#post-17963634)
 * Hello [@antonynz](https://wordpress.org/support/users/antonynz/) 
   This is Divyang
   from The Plus Addons team. Thank you for bringing this to our attention. I would
   like to inform you that our team is working on new dashboard and will address
   all such issues in that. This update will be included in the upcoming release
   of The Plus Addons. I kindly ask for your patience. In the meantime, please let
   us know if you have any concerns. Best Regards.
 *  Plugin Support [Divyang Chaudhary](https://wordpress.org/support/users/divyangposimyth/)
 * (@divyangposimyth)
 * [1 year, 6 months ago](https://wordpress.org/support/topic/echo-used-in-wp_enqueue_scripts/#post-18161614)
 * Hello [@antonynz](https://wordpress.org/support/users/antonynz/) 
   Thank you for
   your patience.
 * Our team has fixed the issues and released a new version 6.0.8. Can you please
   check and confirm the same?
 * Looking forward to your response.
 * Best Regards.
 *  Thread Starter [Antony Booker](https://wordpress.org/support/users/antonynz/)
 * (@antonynz)
 * [1 year, 6 months ago](https://wordpress.org/support/topic/echo-used-in-wp_enqueue_scripts/#post-18162817)
 * I wasn’t able to replicate the sitemap issue. However the function and that file
   is the same from what I can see? As it’s called within wp_enqueue_scripts it 
   might have unexpected problems and conflicts. 
   The two issues are:1. content 
   echo’d in wp_enqueue_scripts 2. wp_print_inline_script_tag used incorrectly with
   an “echo” in frontSomething like this would be more suitable if you are wanting
   to output javascript variables to the page when loading a javascript file:
 *     ```wp-block-code
       public function load_inline_script() {    $script_handle = 'your-main-script-handle'; // Replace with the handle of your enqueued script    $js_inline = '        var theplus_ajax_url = "' . admin_url("admin-ajax.php") . '";        var theplus_ajax_post_url = "' . admin_url("admin-post.php") . '";        var theplus_nonce = "' . wp_create_nonce("theplus-addons") . '";    ';    wp_add_inline_script($script_handle, $js_inline);}
       ```
   
 * Or if only the inline script is needed the script could be loaded using the wp_head
   action:
 *     ```wp-block-code
       public function load_inline_script() {    add_action('wp_head', function() {        ?>        <script type="text/javascript">            var theplus_ajax_url = "<?php echo esc_url(admin_url('admin-ajax.php')); ?>";            var theplus_ajax_post_url = "<?php echo esc_url(admin_url('admin-post.php')); ?>";            var theplus_nonce = "<?php echo esc_js(wp_create_nonce('theplus-addons')); ?>";        </script>        <?php    });}
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘echo used in wp_enqueue_scripts’ is closed to new replies.

 * ![](https://ps.w.org/the-plus-addons-for-elementor-page-builder/assets/icon-256x256.
   gif?rev=2698100)
 * [The Plus Addons for Elementor - Addons for Elementor, Page Templates, Widgets, Mega Menu, WooCommerce](https://wordpress.org/plugins/the-plus-addons-for-elementor-page-builder/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/the-plus-addons-for-elementor-page-builder/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/the-plus-addons-for-elementor-page-builder/)
 * [Active Topics](https://wordpress.org/support/plugin/the-plus-addons-for-elementor-page-builder/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/the-plus-addons-for-elementor-page-builder/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/the-plus-addons-for-elementor-page-builder/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Antony Booker](https://wordpress.org/support/users/antonynz/)
 * Last activity: [1 year, 6 months ago](https://wordpress.org/support/topic/echo-used-in-wp_enqueue_scripts/#post-18162817)
 * Status: not resolved