/*!
Theme Name: UiCore Pro Child
Theme URI: https://uicore.co
Description: One framework for all your website needs.
Author: UiCore
Author URI: https://uicore.co
Template: uicore-pro
Version: 1.0.0
Text Domain: uicore-pro
*/

 /* Add your custom style here */
/**
 * Nicht-kritisches CSS asynchron laden.
 * Voraussetzung: UiCore -> Performance -> "Enable Inline Critical CSS" ist aktiv.
 */
add_filter( 'style_loader_tag', function ( $tag, $handle ) {

	// Backend, Customizer und Elementor-Editor unangetastet lassen.
	if ( is_admin() || is_customize_preview() ) {
		return $tag;
	}
	if ( class_exists( '\Elementor\Plugin' ) && \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
		return $tag;
	}

	// Nur diese Handles werden nachgeladen. Konservative Startliste.
	$defer = array(
		'font-awesome-5-all',
		'font-awesome-4-shim',
		'bdt-uikit',
		'ep-helper',
		'responsive-lightbox-swipebox',
		'cute-alert',
		'text-editor-style',
		'metform-pro-style',
		'widget-for-eventbrite-api',
		'widget-for-eventbrite-api-frontend',
		'widget-for-eventbrite-api-elementor-css',
		'trp-language-switcher-style',
		'ui-e-carousel',
		'ui-e-animation',
		'ui-e-entrance',
		'ui-e-icon-box',
		'ui-e-logo-carousel',
		'ui-e-accordion',
		'ui-e-testimonial-carousel',
		'ui-e-testimonial-slider',
		'ui-e-post-grid',
		'e-shapes',
		'e-animation-fadeIn',
		'widget-pp-icon-list',
		'widget-menu-anchor',
		'uicore-blog-st',
		'uicore_blog_grid_fonts',
	);

	if ( ! in_array( $handle, $defer, true ) ) {
		return $tag;
	}

	$noscript = '<noscript>' . $tag . '</noscript>';

	$tag = str_replace(
		"rel='stylesheet'",
		"rel='preload' as='style' onload=\"this.onload=null;this.rel='stylesheet'\"",
		$tag
	);
	$tag = str_replace(
		'rel="stylesheet"',
		'rel="preload" as="style" onload="this.onload=null;this.rel=\'stylesheet\'"',
		$tag
	);

	return $tag . $noscript;
}, 10, 2 );
add_action( 'wp_head', function () {
	$base = get_site_url() . '/wp-content/uploads/elementor/google-fonts/fonts/';
	echo '<link rel="preload" as="font" type="font/woff2" crossorigin href="'
		. $base . 'opensans-memvyags126mizpba-uvwbx2vvnxbbobj2ovts-muw.woff2">' . "\n";
	echo '<link rel="preload" as="font" type="font/woff2" crossorigin href="'
		. $base . 'opensans-memvyags126mizpba-uvwbx2vvnxbbobj2ovtugmu1ab.woff2">' . "\n";
}, 1 );