Enqueue
**Site relevance:** 2IA.org
**Memory type:** theme source memory
**Source path:** 2IA.org/wp-content/themes/twoia-intelligence/inc/enqueue.php
**Size:** 1.4 KB
Summary
if ( ! defined( 'ABSPATH' ) )
Source Preview
This source file is short enough to preview directly on its source-memory page.
<?php
/**
* Asset loading.
*
* @package TwoIA
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Return a cache-busting file version.
*
* @param string $relative_path Relative path inside the theme.
* @return string
*/
function twoia_asset_version( $relative_path ) {
$file = get_template_directory() . '/' . ltrim( $relative_path, '/' );
if ( file_exists( $file ) ) {
return (string) filemtime( $file );
}
return TWOIA_THEME_VERSION;
}
/**
* Enqueue theme assets. No Bootstrap, jQuery, CDNs, external fonts, or tracking.
*/
function twoia_enqueue_assets() {
wp_enqueue_style(
'twoia-theme',
get_template_directory_uri() . '/assets/css/theme.css',
array(),
twoia_asset_version( 'assets/css/theme.css' )
);
wp_enqueue_script(
'twoia-theme',
get_template_directory_uri() . '/assets/js/theme.js',
array(),
twoia_asset_version( 'assets/js/theme.js' ),
true
);
}
add_action( 'wp_enqueue_scripts', 'twoia_enqueue_assets' );
/**
* Defer the theme JavaScript file.
*
* @param string $tag Script tag.
* @param string $handle Script handle.
* @param string $src Script source URL.
* @return string
*/
function twoia_defer_theme_script( $tag, $handle, $src ) {
if ( 'twoia-theme' !== $handle ) {
return $tag;
}
return '<script src="' . esc_url( $src ) . '" defer></script>' . "\n";
}
add_filter( 'script_loader_tag', 'twoia_defer_theme_script', 10, 3 );