/** * Enqueue scripts and styles de forma organizada. */ function blessing_scripts() { // 1. Variables de configuración $mapapikey = function_exists('blessing_get_option') ? blessing_get_option('mapapikey') : ''; $has_animation = function_exists('blessing_get_option') && blessing_get_option('blessing_animation'); // --- SECCIÓN CSS --- // Fuentes externas wp_enqueue_style( 'blessing-fonts', blessing_fonts_url(), array(), null ); // Base: Normalize y Bootstrap wp_enqueue_style( 'blessing-normalize', get_theme_file_uri( '/assets/css/normalize.min.css' ), array(), '1.0' ); wp_enqueue_style( 'blessing-bootstrap-css', get_theme_file_uri( '/assets/css/bootstrap.css' ), array('blessing-normalize'), '1.0' ); // Iconos: Prioridad a FontAwesome de VC si existe if ( wp_style_is( 'vc_font_awesome_5', 'registered' ) ) { wp_enqueue_style( 'vc_font_awesome_5' ); } else { wp_enqueue_style( 'blessing-font-awesome', get_theme_file_uri( '/assets/css/font-awesome.min.css' ), array(), '1.0' ); } // Componentes (dependen de bootstrap) wp_enqueue_style( 'blessing-owl-carousel', get_theme_file_uri( '/assets/css/owl.carousel.css' ), array('blessing-bootstrap-css'), '1.0' ); wp_enqueue_style( 'blessing-magnific-css', get_theme_file_uri( '/assets/css/magnific-popup.css' ), array('blessing-bootstrap-css'), '1.0' ); wp_enqueue_style( 'blessing-mediaelementplayer', get_theme_file_uri( '/assets/css/mediaelementplayer.css' ), array('blessing-bootstrap-css'), '1.0' ); if ( $has_animation ) { wp_enqueue_style( 'blessing-animate', get_theme_file_uri( '/assets/css/animate.min.css' ), array('blessing-bootstrap-css'), '1.0' ); } if ( class_exists('woocommerce') ) { wp_enqueue_style( 'blessing-woocommerce', get_template_directory_uri() . '/assets/css/woocommerce.css', array('blessing-bootstrap-css'), '1.0' ); } // Estilo principal del tema (SIEMPRE AL FINAL para poder sobrescribir) wp_enqueue_style( 'blessing-style', get_stylesheet_uri(), array('blessing-bootstrap-css'), null ); // --- SECCIÓN JAVASCRIPT --- // WordPress ya trae jQuery, solo hay que llamarlo wp_enqueue_script( 'jquery' ); // Modernizr suele ir en el (false) wp_enqueue_script( 'blessing-modernizr', get_theme_file_uri( '/assets/js/modernizr.custom.js' ), array(), '1.0', false ); // Librerías base wp_enqueue_script( 'blessing-bootstrap-js', get_theme_file_uri( '/assets/js/bootstrap.min.js' ), array('jquery'), '1.0', true ); wp_enqueue_script( 'blessing-magnific', get_theme_file_uri( '/assets/js/magnific-popup.js' ), array('jquery'), '1.0', true ); wp_enqueue_script( 'blessing-mediaelement', get_theme_file_uri( '/assets/js/mediaelement-and-player.js' ), array('jquery'), '1.0', true ); wp_enqueue_script( 'blessing-countdown', get_theme_file_uri( '/assets/js/jquery.countdown.min.js' ), array('jquery'), '1.0', true ); if ( $has_animation ) { wp_enqueue_script( 'blessing-wow', get_theme_file_uri( '/assets/js/wow.min.js' ), array(), '1.0', true ); } // Archivo de plugins consolidado $plugins_deps = array('jquery', 'blessing-bootstrap-js'); wp_enqueue_script( 'blessing-plugins', get_theme_file_uri( '/assets/js/plugins.js' ), $plugins_deps, '1.0', true ); // Scripts de la interfaz del tema (UI) wp_enqueue_script( 'blessing-main', get_template_directory_uri() . '/assets/js/ui/blessing-popups.js', array('jquery', 'blessing-plugins'), null, true ); wp_enqueue_script( 'blessing-masonry', get_template_directory_uri() . '/assets/js/ui/blessing-masonry.js', array('jquery', 'blessing-plugins'), null, true ); wp_enqueue_script( 'blessing-hover', get_template_directory_uri() . '/assets/js/ui/blessing-hover.js', array('jquery', 'blessing-plugins'), null, true ); // Script Custom Final (el que inicializa todo) $custom_deps = array('jquery', 'blessing-plugins', 'blessing-main'); wp_enqueue_script( 'blessing-custom', get_theme_file_uri( '/assets/js/blessing-custom.js' ), $custom_deps, '1.0', true ); // Google Maps (solo si hay API Key) if ( ! empty( $mapapikey ) ) { wp_enqueue_script( 'blessing-mapapi', 'https://maps.googleapis.com/maps/api/js?key=' . rawurlencode($mapapikey), array(), null, true ); } // Comentarios if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); } } add_action( 'wp_enqueue_scripts', 'blessing_scripts' );