Title: Enqueue external php and css from Code Snippets
Last modified: April 28, 2025

---

# Enqueue external php and css from Code Snippets

 *  [hebhansen](https://wordpress.org/support/users/hebhansen/)
 * (@hebhansen)
 * [1 year ago](https://wordpress.org/support/topic/enqueue-external-php-and-css-from-code-snippets/)
 * Hi Fixers
 * I am trying to enqueue external php and css from within my theme TT5:
    1. I wish to maintain the themes design, hence, child theme is not an option
    2. I wish to do my coding external in VSC and can live with an enqueue file, not
       accessible from vsc.
    3. I wish to have ALL custom files inside one designated folder, so that it can
       be easily transferred when upgrading to TT6.
 * So I have added an enqueue file to code snippets, but I do not think it executes,
   so I wonder if a sharp mind can inform me, that this is not possible or maybe
   locate, what is blocking my enqueue from working. Please note Code Snippets applies
   the opening php tag by default, therefore, it is not here
 *     ```wp-block-code
       /******************************************************************* ********** Enqueue functions - functions.php includes ************* ********* Sub functions may be targeted conditionally ************* ******************************************************************/function draupnir_9_enqueue_plugin_functions() {    // Include theme setup functions    require_once get_template_directory() . '/assets/theme-setup.php';    // Include custom post types functions    require_once get_template_directory() . '/assets/custom-post-types.php';    // Include other custom functions    require_once get_template_directory() . '/assets/custom-functions.php';    // Optionally, include admin-specific functionality    if ( current_user_can( 'administrator' ) || current_user_can( 'shop_manager' ) || current_user_can( 'editor' ) ) {        require_once get_template_directory() . '/assets/admin-functions.php';    }    // Check if WooCommerce is active and include its functions    if ( class_exists( 'WooCommerce' ) ) {        $file_path = get_template_directory() . '/assets/woocommerce-functions.php';        if ( file_exists( $file_path ) ) {            require_once $file_path;        }    }    // Check if WCFM Marketplace plugin is active    if ( is_plugin_active( 'wc-multivendor-marketplace/wc-multivendor-marketplace.php' ) ) {        // Include general WCFM functions        $file_path = get_template_directory() . '/assets/wcfm-functions.php';        if ( file_exists( $file_path ) ) {            require_once $file_path;        }        // Include vendor-specific functions        if ( current_user_can( 'wcfm_vendor' ) || current_user_can( 'administrator' ) || current_user_can( 'shop_manager' ) || current_user_can( 'editor' ) ) {            $file_path = get_template_directory() . '/assets/draupnir-9/includes/wcfm-vendor-functions.php';            if ( file_exists( $file_path ) ) {                require_once $file_path;            }        }        // Include admin-specific functions        if ( current_user_can( 'administrator' ) || current_user_can( 'shop_manager' ) || current_user_can( 'editor' ) ) {            $file_path = get_template_directory() . '/assets/draupnir-9/includes/wcfm-admin-functions.php';            if ( file_exists( $file_path ) ) {                require_once $file_path;            }        }    }    // Check if Amelia Booking is active and include it's functions    if ( class_exists( 'Amelia\Classes\Context' ) ) {        $file_path = get_template_directory() . '/assets/amelia-functions.php';        if ( file_exists( $file_path ) ) {            require_once $file_path;        } else {            // Log error and notify admin via email            $error_message = 'Amelia functions file not found: ' . $file_path;            error_log( $error_message );            // Send email notification            send_admin_email_notification( 'Error: Missing Amelia Functions File', $error_message );        }    }    // Include enqueue scripts/styles    require_once get_template_directory() . '/assets/enqueue-scripts.php';}// Hook the function to an appropriate actionadd_action( 'init', 'draupnir_9_enqueue_plugin_functions' );//add_action( 'after_setup_theme', 'draupnir_9_enqueue_plugin_functions' );// Custom Settingsadd_theme_support( 'block-templates' );});
       ```
   
 * So this file would work in my child theme, where get_template_directory would
   be get_stylesheet_directory where:
 * `get_template_directory()` → Always points to the **parent theme** folder.
 * `get_stylesheet_directory()` → Points to the **currently active theme**, which
   could be a child or the parent if no child is used.
 * So I am not sure these enques execute. I have checked in Query Monitor plugin,
   but I do not see any of them loading. The source files do exist at the correct
   location.
 * Any ideas. Thx

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

 *  Thread Starter [hebhansen](https://wordpress.org/support/users/hebhansen/)
 * (@hebhansen)
 * [1 year ago](https://wordpress.org/support/topic/enqueue-external-php-and-css-from-code-snippets/#post-18439929)
 * Also I wonder if it is possible to extend theme’s theme.json somehow? Meaning
   extend the existing without overwriting it.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [1 year ago](https://wordpress.org/support/topic/enqueue-external-php-and-css-from-code-snippets/#post-18444116)
 * Hiya hebhansen,
    FYI, in the WP vernacular, only CSS and JS external files are“
   enqueued”. PHP is not “enqueued” in this sense. I think I understand what you
   want to do though.
 * > I wish to maintain the themes design, hence, child theme is not an option
 * I don’t see how this could be so. There’s no reason a child theme cannot inherit
   the parent theme’s design.
 * Anyway, to avoid a child theme, you can achieve most customization via a custom
   plugin. When a plugin is loaded, only its main file executes (the file named 
   after the plugin’s name). If you want any other PHP files to also execute, you
   must include or require those files from the main file (or establish a include/
   require chain). You may register and/or enqueue any CSS or JS files with any 
   PHP code that executes before or during the “init” action.
 * The main reason for using a child theme instead of a plugin is WP will not look
   for template files in a plugin. Nearly anything else can be accomplished by plugin.
   Even templates can come from a plugin, except you must load them yourself, WP
   will not find them on its own.
 * I believe if you had a child theme, its theme.json extends the parent’s theme.
   json. Unconfirmed though, I’ve not verified this to be true. You could create
   a minimal child theme just to see what works and what doesn’t. There’s nothing
   saying you have to actually use it 🙂 OTOH, I’m fairly sure there’s no way to
   extend a theme’s theme.json via plugin. Plugins would have to implement such 
   things via CSS and JS. Again, unconfirmed.
 *  Thread Starter [hebhansen](https://wordpress.org/support/users/hebhansen/)
 * (@hebhansen)
 * [1 year ago](https://wordpress.org/support/topic/enqueue-external-php-and-css-from-code-snippets/#post-18464637)
 * Hi [@bcworkz](https://wordpress.org/support/users/bcworkz/) . Good to see you
   are still around and thx for your reply….
 * So I have messed with child theme under TT4 and then under TT5. theme.json was
   supposed to add child styles (Extend) to the styles of parent. It does not. It
   overwrites and only custom styles such as colour shows. Also while custom theme.
   json is maturing it has a lot of hick-ups and issues still.
 * Hence, I just want to extend theme.json in my personal custom folder inside theme
   TT5. I want a single folder, to simply drop it into a new theme when moving on
   to the next. Question is, can I extend/not overwrite t.json and how?
 * Parent styles apply to child theme… They do not in my case. It’s my understanding
   a child is styled from the ground up???? And that I do not want.
 * Site [running from child](https://svalinnart.com/). Note headings. (Not working)
 * Site [running from parent](https://heptados.com/). Note headings. (Working)
 * So all I want is to enqeueu from within the parent theme and drop the child. 
   Why enqeue. Cause I want to code in VSC and not in code snippets. However, I 
   use code snippets to perform the enqeueu.
 * Enqeue php files in Code Snippets: Are you saying this cannot be done?
 * Enqeue css/js in code snippets: This i can do?
 * Thx H
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [1 year ago](https://wordpress.org/support/topic/enqueue-external-php-and-css-from-code-snippets/#post-18470768)
 * Adding a custom folder to a theme that’s subject to periodic updates is problematic.
   Updates could remove your folder. In any case it’d be no more effective than 
   a child theme, and you still cannot extend theme.json as you wish.
 * You can achieve most front end and some back end customization from a bespoke
   plugin. The theme can be left as-is. The notable exception is you still cannot
   properly extend theme.json. However, it is feasible to manipulate the editor 
   DOM via JavaScript or one of its extensions like jQuery, React, etc. This in 
   a sense would “extend” theme.json, except its very paradigm is unavailable, you’d
   instead manipulate the resulting DOM. For example, you could use JS to alter 
   some of the default background colors that are selectable in block settings. 
   However, doing so gets rather tricky because the target DOM elements are not 
   immediately available on page load. You’d need to hook into some event that is
   triggered when the related block settings are loaded.
 * Regardless of which style is chosen and applied in the editor, it’s still possible
   to override most styles on the front end by applying custom CSS. Styles that 
   appear as element attribute styles however are difficult to override with custom
   CSS. Those are best overridden with custom JS. Thus the only reason to alter 
   the editor styles is for user experience, your desired styles can be forced on
   the front end regardless of what was selected in the editor.
 * You may compose your code with any editor you wish, as long as the result is 
   a plain text file. You don’t really even need a code snippets plugin. Any additional
   PHP code can execute directly from a bespoke plugin.

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

The topic ‘Enqueue external php and css from Code Snippets’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [1 year ago](https://wordpress.org/support/topic/enqueue-external-php-and-css-from-code-snippets/#post-18470768)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
