Title: Cross Snippet Functions
Last modified: March 31, 2021

---

# Cross Snippet Functions

 *  [dylanbanta](https://wordpress.org/support/users/dylanbanta/)
 * (@dylanbanta)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/cross-snippet-functions/)
 * I’ve been trying to create a utility php script that holds functions that I use
   often. It seems I can’t call functions from one snippet in another snippet.
 * For example this snippet
    `[xyz-ips snippet="Utils"]`
 *     ```
       <?php
       function writeMsg() {
         echo "Hello world!";
       }
       ?>
       ```
   
 * cannot be called by this snippet
 * `[xyz-ips snippet="UtilCaller"]`
 *     ```
       <?php
       writeMsg();
       ?>
       ```
   
 * Edit:
    Been looking through the support section of the forums and came across
   [this post](https://wordpress.org/support/topic/need-global-scope-of-php-variables-between-snippets/).
 * In the post you mention using global variables with
    `$GLOBALS[‘your_variable’]
   =”something”;`
 * Is there a similar methodology for functions?
    -  This topic was modified 5 years, 2 months ago by [dylanbanta](https://wordpress.org/support/users/dylanbanta/).
    -  This topic was modified 5 years, 2 months ago by [dylanbanta](https://wordpress.org/support/users/dylanbanta/).
    -  This topic was modified 5 years, 2 months ago by [dylanbanta](https://wordpress.org/support/users/dylanbanta/).

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

 *  Thread Starter [dylanbanta](https://wordpress.org/support/users/dylanbanta/)
 * (@dylanbanta)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/cross-snippet-functions/#post-14318535)
 * Still seeking an answer.
 *  Plugin Author [f1logic](https://wordpress.org/support/users/f1logic/)
 * (@f1logic)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/cross-snippet-functions/#post-14354800)
 * I guess you will have to write those functions in a separate php file, place 
   it in some folder and use the include_once keyword to include that file in your
   snippets.
 *  Thread Starter [dylanbanta](https://wordpress.org/support/users/dylanbanta/)
 * (@dylanbanta)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/cross-snippet-functions/#post-14356113)
 * I’ll give that a shot and see how it works, thanks!

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

The topic ‘Cross Snippet Functions’ is closed to new replies.

 * ![](https://ps.w.org/insert-php-code-snippet/assets/icon-128x128.png?rev=1800967)
 * [Insert PHP Code Snippet](https://wordpress.org/plugins/insert-php-code-snippet/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/insert-php-code-snippet/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/insert-php-code-snippet/)
 * [Active Topics](https://wordpress.org/support/plugin/insert-php-code-snippet/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/insert-php-code-snippet/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/insert-php-code-snippet/reviews/)

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)

 * 3 replies
 * 2 participants
 * Last reply from: [dylanbanta](https://wordpress.org/support/users/dylanbanta/)
 * Last activity: [5 years, 1 month ago](https://wordpress.org/support/topic/cross-snippet-functions/#post-14356113)
 * Status: not resolved