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 '
';
foreach ( $langs as $lang ) {
printf(
'- %s
',
esc_url( $lang['url'] ),
esc_attr( $lang['slug'] ),
esc_attr( $lang['slug'] ),
$lang['current_lang'] ? ' aria-current="true" class="is-current"' : '',
esc_attr( $lang['name'] ),
esc_html( strtoupper( $lang['slug'] ) )
);
}
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' ) );
}
function ga_brand() {
if ( has_custom_logo() ) {
the_custom_logo();
return;
}
printf(
'%s%s%s%s',
esc_url( ga_home_url() ),
ga_icon( 'mark' ), // SVG estático.
esc_html( ga_opt( 'header', 'brand_line1' ) ),
esc_html( ga_opt( 'header', 'brand_line2' ) ),
esc_html( ga_opt( 'header', 'brand_line3' ) )
);
}
/* ---------- Ayudantes de animales ---------- */
function ga_status_badge( $post_id = null ) {
$post_id = $post_id ?: get_the_ID();
$estado = ga_get( $post_id, 'estado' ) ?: 'disponible';
$label = ga_label( $post_id, 'estado' ) ?: ga__( 'En adopción', 'Adopzioan' );
printf( '%s', esc_attr( $estado ), esc_html( $label ) );
}
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_icon( 'paw' ) . '
';
}
}
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';
}
/** «Bien con niños» / «Haurrekin ondo» a partir de la etiqueta «Niños» / «Haurrak». */
function ga_compat_label( $label ) {
$label = mb_strtolower( $label );
if ( 'eu' === ga_lang() ) {
return mb_strtoupper( mb_substr( $label, 0, 1 ) ) . mb_substr( preg_replace( '/ak$/u', 'ekin', $label ), 1 ) . ' ondo';
}
return 'Bien con ' . $label;
}
/** 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' ) );