/home/bdqbpbxa/rc-subdomains/brnr-rc.goodface.com.ua/wp-content/themes/burner/inc/enqueue.php
<?php
add_action('wp_enqueue_scripts','inc_style');
function inc_style(){
$version = '2.8';
if(is_page_template( 'tpl-referral.php' )){
custom_enqueu_style('tpl_referral', '/assets/css/', 'tpl-referral.css', [
'tpl-referral.critical.css'
], $version);
wp_enqueue_style('fullpage_css', get_template_directory_uri() . '/src/css/fullpage.css', array(), $version);
} else {
custom_enqueu_style('front_css', '/assets/css/', 'front-page.css', [
'front-page.critical.css',
'post.critical.css'
], $version);
wp_enqueue_style('fullpage_css', get_template_directory_uri() . '/src/css/fullpage.css',array(), $version);
}
}
add_action('wp_footer', 'scripts_site');
function scripts_site()
{
$version = '2.8';
wp_enqueue_script('lozad_js', 'https://cdn.jsdelivr.net/npm/lozad/dist/lozad.min.js"', array('jquery'), $version, true);
wp_enqueue_script('fullpage_js', get_template_directory_uri() . '/src/js/fullpage.min.js', array(), $version, true);
wp_enqueue_script('front_js', get_hash_file('/assets/js/', 'front-page.js'), array('fullpage_js'), $version, true);
}
//add_action('wp_enqueue_scripts', 'shapeSpace_include_custom_jquery');
// ======================================
function custom_enqueu_style($handle, $path, $file, array $critical_files, $version = null)
{
$critical_style = '';
foreach ($critical_files as $critical_file) {
$check_file = get_template_directory() . $path . $critical_file;
if(file_exists($check_file)){
$critical_style .= file_get_contents($check_file);
}
}
if ($critical_style != '') {
if(!empty($critical_style)){
add_action('wp_head', function () use ($critical_style) {
echo "<style>$critical_style</style>";
});
add_action('wp_footer', function () use ($handle, $path, $file, $version) {
wp_enqueue_style($handle, get_hash_file($path,$file), array(), $version);
});
}
}else{
wp_enqueue_style($handle, get_hash_file($path, $file), array(), $version);
}
}
function get_hash_file($path, $name)
{
if (is_admin()) {
return;
}
$hash_path = get_template_directory_uri() . $path . $name;
$entry_points = get_template_directory() . $path . 'entrypoints.json';
if (file_exists($entry_points)) {
$entrypoints_data = file_get_contents($entry_points);
$entrypoints_data = json_decode($entrypoints_data, true);
foreach ($entrypoints_data as $key => $value) {
if ($key == $name) {
$hash_path = get_template_directory_uri() . $path . $value;
}
}
}
return $hash_path;
}
// ======================================
function add_async_attribute($tag, $handle)
{
if ('front_js' !== $handle) {
return $tag;
}
return str_replace(' src', ' async="async" src', $tag);
}
add_filter('script_loader_tag', 'add_async_attribute', 10, 2);