<?php
/*
Theme Name: Usina #99 - Todos Brujos
Theme URL: http://hostinger-tutorials.com
Description: Todos Brujos
Author: John Doe
Author URL: http://hostinger-tutorials.com
Template: u99
Version: 1.0.0
Text Domain: u99-todos-brujos-child
*/

//add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles', 12 );

function u99_scripts() {
    $parenthandle = 'parent-style';
    wp_dequeue_style( 'wp-block-library' );
    wp_dequeue_style( 'wp-block-library-theme' );
    wp_dequeue_style( 'wc-block-style' );
    wp_deregister_script('jquery');


    //wp_enqueue_script('jquery', get_template_directory_uri() . '/js/jquery-3.4.1.min.js', array(), '3.4.1');
    wp_enqueue_script('jquery', get_theme_file_uri() . '/js/jqueryMinimo.min.js', array(), '3.4.1');
    //wp_enqueue_script('jquery', get_theme_file_uri() . '/js/jqueryMinimo.js', array(), '3.4.1');
    wp_enqueue_style( 'u99-boostrap-style', get_theme_file_uri( '/css/bootstrapMinimo.min.css' ), array(), wp_get_theme()->get( 'Version' ) );
    
    //wp_enqueue_style( $parenthandle, get_template_directory_uri().'/style.css' );
    wp_enqueue_style( 'u99-style', get_theme_file_uri('/css/styleParent.min.css'), array(), wp_get_theme()->get( 'Version' ) );
    wp_enqueue_style( 'u99-todos-brujos-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
    //wp_enqueue_script('jquery-custom', get_theme_file_uri() . '/js/custom.min.js', array(), '3.4.1');
    //wp_enqueue_script('jquery-custom', get_theme_file_uri() . '/js/custom.js', array(), '3.4.1');
}


add_filter('style_loader_tag', 'u99_style_loader_tag_filter',10,4);

function u99_style_loader_tag_filter($html, $handle, $href, $media) {

  switch ($handle) {
    case 'u99-boostrap-style':
    case 'u99-style':
    case 'u99-todos-brujos-style':
    case 'contact-form-7':
        return str_replace("rel='stylesheet'", "rel='preload' as='style' onload=" . '"' . "this.onload=null;this.rel='stylesheet'" . '"', $html);
        break;
    default:
        return $html;
        break;
  }

}


add_filter('script_loader_tag', 'u99_script_loader_tag_filter',10,4);
function u99_script_loader_tag_filter($tag, $handle, $src) {
  //echo "<p>BGA:".$handle."</p>";
  switch ($handle) {
    case 'jquery':
    case 'jquery-custom':
    case 'contact-form-7':
    case 'wp-embed':  
        return str_replace("type='text/javascript'", "type='text/javascript' async defer", $tag);
        break;
    default:
        return $tag;
        break;
  }

}
