120, 'width' => 120, 'flex-width' => true, 'flex-height' => true ) ); add_theme_support( 'html5', array( 'search-form', 'gallery', 'caption', 'style', 'script' ) ); add_theme_support( 'align-wide' ); add_theme_support( 'responsive-embeds' ); add_theme_support( 'editor-styles' ); add_theme_support( 'wp-block-styles' ); add_theme_support( 'customize-selective-refresh-widgets' ); add_editor_style( 'style.css' ); add_image_size( 'ga-card', 640, 544, true ); add_image_size( 'ga-square', 1000, 1000, true ); register_nav_menus( array( 'primary' => 'Menú principal', 'footer' => 'Menú legal (pie)', ) ); } ); add_action( 'wp_enqueue_scripts', function () { wp_enqueue_style( 'gure-ametsa', get_stylesheet_uri(), array(), GA_THEME_VERSION ); wp_enqueue_script( 'gure-ametsa', get_theme_file_uri( 'assets/js/main.js' ), array(), GA_THEME_VERSION, array( 'strategy' => 'defer', 'in_footer' => true ) ); } ); add_action( 'wp_head', function () { echo '' . "\n"; if ( ! has_site_icon() ) { echo '' . "\n"; } }, 1 ); /** Portada en el idioma actual. */ function ga_home_url() { return function_exists( 'pll_home_url' ) ? pll_home_url() : home_url( '/' ); } /* ---------- Selector de idioma ---------- */ function ga_language_switcher( $class = 'ga-lang' ) { if ( ! function_exists( 'pll_the_languages' ) || ! ga_opt( 'header', 'switcher' ) ) { return; } $langs = pll_the_languages( array( 'raw' => 1, 'hide_if_empty' => 0, 'hide_if_no_translation' => 0 ) ); if ( ! $langs ) { return; } echo ''; } /* ---------- Iconos SVG ---------- */ function ga_icon( $name ) { $icons = array( 'paw' => '', 'mark' => '', 'instagram' => '', 'facebook' => '', 'tiktok' => '', 'youtube' => '', 'whatsapp' => '', 'phone' => '', 'mail' => '', 'pin' => '', 'clock' => '', 'arrow' => '', 'check' => '', 'menu' => '', ); return $icons[ $name ] ?? ''; } /** Enlaces a redes sociales configuradas en el personalizador. */ function ga_social_links( $with_labels = false ) { $networks = array( 'instagram' => 'Instagram', 'facebook' => 'Facebook', 'tiktok' => 'TikTok', 'youtube' => 'YouTube', 'whatsapp' => 'WhatsApp', ); $out = ''; foreach ( $networks as $key => $label ) { $value = ga_info( $key ); if ( ! $value ) { continue; } $href = 'whatsapp' === $key ? 'https://wa.me/' . preg_replace( '/\D/', '', $value ) : $value; $out .= sprintf( '%s%s', esc_url( $href ), esc_attr( $label ), ga_icon( $key ), $with_labels ? ' ' . esc_html( $label ) : '' ); } return $out; } function ga_tel_link() { return 'tel:+34' . preg_replace( '/\D/', '', ga_info( 'telefono' ) ); } /** SVG del logo (assets/img/logo.svg o logo-mark.svg), en línea para poder recolorearlo con CSS. */ function ga_logo_svg( $variant = 'full' ) { static $cache = array(); if ( ! isset( $cache[ $variant ] ) ) { $file = get_theme_file_path( 'assets/img/' . ( 'mark' === $variant ? 'logo-mark.svg' : 'logo.svg' ) ); $cache[ $variant ] = is_readable( $file ) ? trim( file_get_contents( $file ) ) : ''; } return $cache[ $variant ]; } /** * Marca del sitio. * * @param string $context 'header' o 'footer'. */ function ga_brand( $context = 'header' ) { if ( has_custom_logo() ) { the_custom_logo(); return; } $style = 'footer' === $context ? 'full' : ga_opt( 'header', 'logo_style' ); $name = sprintf( '%s%s%s', esc_html( ga_opt( 'header', 'brand_line1' ) ), esc_html( ga_opt( 'header', 'brand_line2' ) ), esc_html( ga_opt( 'header', 'brand_line3' ) ) ); $inner = match ( $style ) { 'full' => '', 'text' => $name, default => '' . ga_logo_svg( 'mark' ) . '' . $name, }; printf( '%s', esc_attr( $style ), esc_url( ga_home_url() ), esc_attr( get_bloginfo( 'name' ) ), $inner // SVG estático del tema y textos escapados. ); } /* ---------- Ayudantes de animales ---------- */ /** Distintivo de estado: solo se muestra «En proceso» o «Adoptado» (los disponibles no llevan etiqueta). */ function ga_status_badge( $post_id = null ) { $post_id = $post_id ?: get_the_ID(); $estado = ga_status( $post_id ); if ( 'disponible' === $estado ) { return; } printf( '%s', esc_attr( $estado ), esc_html( ga_label( $post_id, 'estado' ) ) ); } /** Foto principal o, si no hay, la silueta del logo. */ function ga_animal_photo( $size = 'ga-card', $post_id = null ) { $post_id = $post_id ?: get_the_ID(); if ( has_post_thumbnail( $post_id ) ) { echo get_the_post_thumbnail( $post_id, $size, array( 'loading' => 'lazy' ) ); } else { echo '
' . ga_placeholder_svg() . '
'; } } /** Silueta del logo para huecos sin foto. */ function ga_placeholder_svg() { return ga_logo_svg( 'mark' ) ?: ga_icon( 'paw' ); } /** Texto del botón «Quiero conocerlo / conocerla» según el sexo. */ function ga_meet_label( $post_id = null ) { $post_id = $post_id ?: get_the_ID(); return 'hembra' === ga_get( $post_id, 'sexo' ) ? ga_opt( 'adopcion', 'btn_f' ) : ga_opt( 'adopcion', 'btn_m' ); } /** Enlaces para compartir una ficha. */ function ga_share_links( $post_id = null ) { $post_id = $post_id ?: get_the_ID(); $url = get_permalink( $post_id ); $text = get_the_title( $post_id ) . ' — ' . ga__( 'busca familia en Bilagun', 'familia bila Bilagunen' ); printf( '
%sWhatsAppFacebook
', esc_html( ga__( 'Comparte su historia:', 'Partekatu haren istorioa:' ) ), esc_url( 'https://wa.me/?text=' . rawurlencode( $text . ' ' . $url ) ), esc_url( 'https://www.facebook.com/sharer/sharer.php?u=' . rawurlencode( $url ) ), esc_attr( $url ), esc_attr( ga__( '¡Copiado!', 'Kopiatuta!' ) ), esc_html( ga__( 'Copiar enlace', 'Kopiatu esteka' ) ) ); } /** Vídeo de la ficha: oEmbed (YouTube, Vimeo…) o archivo de vídeo. */ function ga_video_html( $url ) { if ( ! $url ) { return ''; } if ( preg_match( '/\.(mp4|webm|mov)(\?.*)?$/i', $url ) ) { return ''; } $embed = wp_oembed_get( $url, array( 'width' => 900 ) ); return $embed ?: '' . esc_html( ga__( 'Ver vídeo', 'Ikusi bideoa' ) ) . ''; } function ga_species( $post_id = null ) { $terms = get_the_terms( $post_id ?: get_the_ID(), 'especie' ); return $terms && ! is_wp_error( $terms ) ? $terms[0]->name : ''; } function ga_plural( $name ) { if ( 'eu' === ga_lang() ) { return preg_match( '/k$/i', $name ) ? $name : $name . 'k'; // Txakurra → Txakurrak, Katua → Katuak. } return preg_match( '/s$/i', $name ) ? $name : $name . 's'; } /** URL de la página de contacto con el animal preseleccionado. */ function ga_adopt_url( $post_id = null ) { return add_query_arg( 'adoptar', $post_id ?: get_the_ID(), ga_page_url( 'contacto' ) ) . '#formulario'; } /** Escapa un texto y convierte *entre asteriscos* en palabras resaltadas. */ function ga_highlight( $text ) { return preg_replace( '/\*(.+?)\*/u', '$1', esc_html( $text ) ); } /** * Encabezado de sección: rayita + antetítulo + título + texto, leídos del personalizador. * * @param string $section Sección del registro. * @param array $args 'center' => bool, 'h' => nivel, 'extra' => HTML a la derecha (p. ej. un botón). */ function ga_section_head( $section, $args = array() ) { $args = wp_parse_args( $args, array( 'center' => false, 'h' => 2, 'extra' => '' ) ); $eyebrow = ga_opt( $section, 'eyebrow' ); $title = ga_opt( $section, 'title' ); $text = ga_opt( $section, 'text' ); if ( ! $eyebrow && ! $title && ! $text ) { return; } printf( '
', $args['center'] ? ' ga-head--center' : '' ); echo '
'; if ( $eyebrow ) { echo '' . esc_html( $eyebrow ) . ''; } if ( $title ) { printf( '%2$s', (int) $args['h'], ga_highlight( $title ) ); } if ( $text ) { echo '

' . esc_html( $text ) . '

'; } echo '
'; echo $args['extra']; // HTML ya escapado por quien llama. echo '
'; } /** Lista de líneas de un textarea del personalizador. */ function ga_lines( $text ) { return array_values( array_filter( array_map( 'trim', explode( "\n", (string) $text ) ) ) ); } /** URL configurable: vacía → valor por defecto; relativa → se respeta. */ function ga_link( $value, $fallback ) { return '' !== trim( (string) $value ) ? $value : $fallback; } /* Título de archivo sin prefijo "Archivo:" */ add_filter( 'get_the_archive_title_prefix', '__return_empty_string' ); /* Extracto corto */ add_filter( 'excerpt_length', fn() => 24 ); add_filter( 'excerpt_more', fn() => '…' ); /* Formato de fecha según idioma */ add_filter( 'option_date_format', fn( $f ) => is_admin() ? $f : ga__( 'j \\d\\e F \\d\\e Y', 'Y\\(\\e\\)\\k\\o F\\r\\e\\n j\\a' ) );