Enqueue external php and css from Code Snippets
-
Hi Fixers
I am trying to enqueue external php and css from within my theme TT5:
- I wish to maintain the themes design, hence, child theme is not an option
- I wish to do my coding external in VSC and can live with an enqueue file, not accessible from vsc.
- 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
/*******************************************************************
********** 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 action
add_action( 'init', 'draupnir_9_enqueue_plugin_functions' );
//add_action( 'after_setup_theme', 'draupnir_9_enqueue_plugin_functions' );
// Custom Settings
add_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
The topic ‘Enqueue external php and css from Code Snippets’ is closed to new replies.